17.3 Command History and Tab Completion 259
Voila!Wenowseethecontentsofsneakers.txt.
The bash shell can store up to 1,000 commands.
Tip: 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, ”HIST-
SIZE=1000” tells us that bash will store 1,000 commands in its history.
The command-line history is actually kept in a file, called .bash
history in our login directory. We
canreaditinanumberofways:byusingpico, cat, less, more, and others.
Be prepared, though: the file can be pretty long.
Let’sreaditwithmore:
more .bash_history
To move forward a screen, press
Space ; to move back a screen, press B ;toquit,press Q .
Another time-saving tool is known as tab completion. If you type part of a file or pathname then hit
the
Tab key, bash will present you with either the remaining portion of a the file/path, or a beep. If
we get a beep, we can press
Tab again to obtain a list of the files/paths that match what we’ve typed
so far.
So even if we do turn off the machine at the end of the day, we probably won’t have to work too
hard in order to remember the command to update locate’s database: The chances are good that the
command will be stored in the command-line history or can be completed with tab completion (as
long as we remember the start of the pathname for the command).
Both tab completion and command-line history can be useful to help you use a command you’ve
forgotten, as well.
Let’s try tab completion to update locate’s database. First, su to root.
Now, at a shell prompt, type the beginning of the path:
/etc/cr
Now, press the
Tab key and tab completion will complete the path to /etc/cron (and you’ll hear
a beep). Press
Tab again, and you’ll be presented with a list of possible completions:
cron.daily cron.hourly cron.monthly cron.weekly crontab
Comments to this Manuals