home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeBook TitleSearch this book

2.2. The History File

All of the Korn shell's command history facilities depend on a file that stores 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.$(tty | sed 's;.*/;;')

This creates a history file whose name ends with the last component of your terminal's device name. For example, your window's terminal device name might be /dev/pts/42. The sed command strips everything through the last slash, leaving just the 42. The history file then becomes ~/.hist.42. You can remove the history file at logout, as explained in Chapter 4. Or you can leave the files around, and your history will be there the next time you start a window on that same terminal device. (Preserving history between sessions is the point of the history file, after all.)

An attractive alternative is to use a single history file for all your windows. Each running instance of the Korn shell is smart enough to share its file with other running instances; from a second window, you can recall and edit the commands run in the first window.

Another environment variable, HISTSIZE, can be used to determine the maximum number of commands accessible from the history file. The default is 128 (i.e., the 128 most recent commands), which should be more than adequate.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.