| « HOWTO: find files on your system | HOWTO: Setup apcupsd with an APC Back-UPS RS 800 » |
When you type a command on in a bash shell, it will be added to a history list. You can use the up and down cursor keys to see each command one at a time. There are also lots of other things you can setup and use to aid you when using the command line.
You can type 'history' and the list will be displayed. The numbers at the beginning of the line can be use to execute the command. Quick and simple ways to use the command line history.
Once you have used the command line for some time and built up a long history list it can be tedious to use the cursor keys or the history command to find the command you are after. The solution is the key combination CTRL+R. This allows you to search the history.
Using the history as an example, say we want to reuse the pdftotoext command again. But cannot remember the command but we do remember that the file was on the Desktop.
Pressing CTRL+R to start the search process off. As you type in the key word the history will be searched and the first command line that matches, working backwards up the list, will be display. So press
CTRL+R and type in Desk,
There you go found it with ease. To use the command line press return. To quit press CTRL+C. You can even edit the command line, by pressing the left or right cursor keys.
The two environment variables HISTSIZE and HISTFILESIZE limit the history size that you will have access to. HISTSIZE limits the entries in the history for any terminal or shell. Once this limit is reached older command lines will be lost until you type them again. The HISTFILESIZE limits the size of the history that
is saved between sessions. When you close shell window down the history is saved by default to your $HOME directory to a file called .bash_history. You can change the file name used with the HISTFILE variable.
These variables should go into your .bash_profile or .profile file. These commands are then executed once when you login. You can put them into your .bashrc but then they are unnecessarily executed every time
you start a shell. Even when the shell in not interactive, ie no command line.
Using the HISTCONTROL variable you can stop some entries from being added such as duplicate entries.
I use the following value to stop any news lines matching from being added and also remove all
duplicated lines.
export HISTCONTROL=ignoreboth
It has the same effect as using both ignorespace and ignoredups. ignorespace will ignore lines which begin with a space so you can use this yourself to stop lines being added. ignoredups will stop duplicate being added if the same command
is used consecutively.
On later versions of bash there is a new option erasedups which causes all previous lines matching the current line to be removed from the history list before that line is saved.
One last variable HISTIGNORE allows you to set some coaamd patterns that will never
be added to the history. You might want to play around with this one but below is a starting example,