| Red Hat Docs > Red Hat Manuals > Archived Red Hat Linux Manuals > |
Command History and Tab CompletionIt doesn't take long before the thought of typing the same command over and over becomes unappealing, at best. Linux users don't feel any differently about that, either. In Linux, since you can string together commands at the shell prompt, one minor typo in a couple lines of a command could mean that all that typing was in vain. So there's a solution: It's called command-line history . By scrolling with the up and down arrow keys, we can find plenty of our previously typed commands -- including the ones with typos. Let's try it by taking a look again at sneakers.txt . The first time, however, at the shell prompt, we'll type:
Nothing happens, of course, because there is no sneakrs.txt file. No problem. We'll 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 Enter again. Voila! 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 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 prepared, though: the file can be pretty long. Let's read it with more :
To move forward a screen, press Space ; to move back a screen, press B ; to quit, press Q .
Another time-saving tool is known as command completion . If you type part of a file, command or pathname then press the Tab key, bash will present you with either the remaining portion of a the file/path, or a beep. If you get a beep, just press Tab again to obtain a list of the files/paths that match what's been typed so far. 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 Tab key twice and you'll see a list of possible completions, including updatedb and uptime . By adding the letter "d" to up and pressing Tab again, your command is completed for you. So even if the machine is turned off at the end of the day, it's not too hard to update the slocate database: The chances are good that the command will be stored in the command-line history or can be completed with command completion (as long as you remember the start of the pathname for the command). |
|||||||||