9.6 Working with the Shell History
In addition to command-line editing features, the Bash shell also provides command-line history support. A list of previously executed commands may be viewed using the history command:
$ history
1 ps
2 ls
3 ls –l /
4 ls
5 man pwd
6 man apropos
In addition, Ctrl-p (or up arrow) and Ctrl-n (or down arrow) may be used to scroll back and forth through previously entered commands. When the desired command from the history is displayed, press the Enter key to execute it.
Another option is to enter the ‘!’ character followed by the first few characters of the command to be repeated followed by the Enter key.