history (display command history)

This shell builtin displays your command history, that is, a list of commands that you executed most recently. Here is an abridged example of its output:

...

1036 touch file.txt

1037 cd /etc

1038 ls

The output shows that the last three commands that I executed were →touch file.txt, →cd /etc and →ls. They are the commands numbered 1036 to 1038 recorded in the shell's history. You can re-execute a command by referring to its number. In our example scenario, you would rerun touch file.txt by entering:

!1036

Alternatively, you can browse and search the history using a variety of keyboard shortcuts (see Appendix B in the printed book).