It’s nice of the shell to remember what you have done, for better or worse. Having the shell keep track of the commands you enter makes it easy to return to those gawd-awfully long commands you pecked at a while ago — even days ago! Let me give you an example. Suppose that yesterday you managed to issue a command to find all the core dump files in your system (core dump files are massive files containing debugging data that only an expert programmer or your computer can understand) and delete them. The command looked something like this:
find / -name core -exec rm {} \;
To re-execute the command, all you need to do is fish it out of your shell his- tory and rerun it. The simplest way to read through your command history line by line is to press the up-arrow key repeatedly until you locate the command you want to re-execute. Then just press the Enter key to run the command again. That’s all there is to it!
You can access your command history in two ways:
-
Press the up-arrow key: This technique is the easiest way to access the history. As soon as you press the up-arrow key, you see all your previous commands light up on the command line. When you find what you’re looking for, just press Enter and you’re cookin’.
-
Enter the history command: The history command lists your last 20 commands (by default) when you enter it at the prompt:
history
Published on Fri 02 March 2001 by Lai Yahui in Linux with tag(s): history