|Red Hat Linux 7.2: The Official Red Hat Linux Getting Started Guide|
|Prev||Chapter 10. Shell Prompt Basics||Next|
It does not take long before the thought of typing the same command over and over becomes unappealing, at best. In Linux, since you can string together commands at the shell prompt, one minor typing error can ruin lines of a command.
One solution is to use the command line history. By scrolling with the up and down arrow keys, you can find plenty of your previously typed commands.
Try it by taking a look again at sneakers.txt (created in the section called Using Redirection. The first time, however, at the shell prompt, type:
Nothing happens, of course, because there is no
sneakrs.txt file. No problem. We will just use the
up-arrow key to bring back the command, then use the left-arrow key to
get to the point where we missed the "e." Insert the letter and press
We now see the contents of sneakers.txt.
By default, up to 500 commands can be stored in the bash command line history file.
|The History Environment Variable|
By typing the env command at a shell prompt, we can see the environment variable that controls the size of the command line history. The line which reads, HISTFILESIZE=500 shows the number of commands that bash will store.
The command line history is actually kept in a file, called .bash_history in our login directory. We can read it in a number of ways: by using pico, cat, less, more, and others.
Be aware that the file can be long.
Let's read it with more:
To move forward a screen, press
|Locating a Previously Used Command|
Want to find a command in your history file without having to keep hitting the arrow keys or page through the history file? Use grep, a powerful search utility (see the section called The grep Command. Here is how you can quickly find a previously used command: Let's say you are searching for the command that was something like cat sneak-something. You have used the command and think it might be in your history file. At the shell prompt, then, type
Another time-saving tool is known as command completion. If you type
part of a file, command, or pathname and then press the
For example, if you forget the command updatedb, but
remember a portion of the command, you can su to
root, then at the shell prompt, type up, press the