You scroll through a long log, close it, and want to repeat your last command. Press the same key in two places and compare what it does.
The log is in the ~/terminal-practice directory. Start on the card creates the directory and takes you into it.
The log and the prompt
In ~/terminal-practice, open the log with less notes.txt and click the terminal. Press the Down arrow a few times, then the Up arrow, and quit with q. Back at the prompt, press the Up arrow again and see what appears on the line.
Why did the Up arrow scroll lines in the log but bring back a command at the prompt?
-
The terminal keeps no commands: it passes keystrokes on and shows text. The last command came from the program that read the arrow at the prompt.
-
While the log is open, the arrows move its lines. The command appeared on the line at the prompt, after q.
-
It did: the log lines moved. Open
less notes.txtagain and press the arrow a few times — the text scrolls.
The arrow was read by the program running at that moment: less in the log, the shell at the prompt.