One solution is to use the command line history. By scrolling with
the
Try it by taking a look again at sneakers.txt (created in Section 13.9.1 Using Redirection. The first time, however, at the shell prompt, type:
cat sneakrs.txt |
Nothing happens, of course, because there is no
sneakrs.txt
We now see the contents of sneakers.txt.
By default, up to 500 commands can be stored in the bash command line history file.
![]() | Tip |
|---|---|
By typing the envHISTFILESIZE=500 shows the number of commands that bash will store. |
The command line history is actually kept in a file, called .bash_history in your login directory. We can read it in a number of ways: by using vi, cat, less, more, and others.
Be aware that the file can be long. To read it with the more command, from your home directory type:
more .bash_history |
To move forward a screen, press
![]() | Tip | |
|---|---|---|
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 Section 13.11.3 The grep Command. Here is how you can quickly find a previously used command: say you are searching for a command that is similar to cat sneak-something. You have used the command, and you think it might be in your history file. At the shell prompt, 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
| Главная |