The shell keeps a list of every line that you send, also the lines that fail. This list is the history.
| You do | What happens |
|---|---|
| Push the up arrow | Your last line comes back after the prompt. Push it again to go one more line back. |
Run history | The shell lists every line, each with a number. The first line has the number 1. |
Run !! | The shell runs the last line again. |
Run !3 | The shell runs line number 3 again. |
Before it runs a line with !, bash shows the line. That line is not output from the command. The output comes after it.
- Run
whoami,hostnameanddate. Then use the up arrow and!!to run lines again. - Show your history and read its numbers.
- Run the line
whoamiagain by its number.