All of the Korn shell's command history facilities depend on a file that contains commands as you type them in. This file is normally .sh_history in your home directory, but you can call it whatever you like by setting the environment variable HISTFILE (see Chapter 3). When you run one of the Korn shell's editing modes, you are actually running a mini-editor on your history file.
If you run more than one login session at a time (e.g., more than one xterm on an X Windows workstation), you may find it advantageous to maintain a separate history file for each login session. Put the following line in your .profile:
HISTFILE=~/.hist$$
This creates a history file whose name begins with .hist and ends with a number that is essentially guaranteed to be unique; see Chapter 8 for an explanation of why .hist$$ generates a unique name. Unfortunately, if you do this, you will end up with lots of stray history files hanging around. One way to clean up the unneeded history files is to clean up after yourself at logout time, as explained in Chapter 4. Another way is to put an entry in your personal crontab file (see the man page crontab(1)) [4] that removes all history files every day at some benign time like 2 A.M. The following line will do it:
[4] Some versions of UNIX do not support personal crontab files, though all versions derived from AT&T System V should. If yours does not, you have two options: either use at with a script that reschedules itself at the end, or ask your system administrator to put an appropriate command in the system's crontab file.
0 2 * * * rm ~/.hist*
Another environment variable, HISTSIZE, can be used to determine the maximum number of commands kept in the history file. The default is 128 (i.e., the 128 most recent commands), which should be more than adequate.