Does the terminal store data?
Solution 1:
This is the command history and it is a feature of the shell rather than the terminal.
On Ubuntu (and a lot if not most of the other Linux distributions) the default shell for interactive use is Bash (/bin/bash
). Bash keeps your history, that is a list of the last commands at ~/.bash_history
. When you open a shell (usually by opening a terminal) this file is read and loaded into the internal history of this shell. Once you close the shell, the changes are written back to the file. By default this is limited to the last 500 commands.
There are a few variables and shell options that can change the behaviour of how this works exactly. Have a look at the bash manpage (man bash
) if you want to know more. Just search for HISTORY (type /^HISTORY
and confirm with Enter, jump to next find with n)
Also there are quite a lot more methods to go around the history than just Up and Down:
For example, press Ctrl+R and part of a previous command, bash will search backwards in the history for a matching command, repeat pressing Ctrl+R if the first match is not the one you are looking for. (See 'Commands for Manipulating the History' in the bash manpage)
Copy
/etc/inputrc
to~/.inputrc
and uncomment the lines withhistory-search-forward
andhistory-search-backward
in them. If you type the first letters of a command and press PgUp, bash will show only commands from the history that start with the same letters. (Work only in shells opened after this change was made)Type
!!
instead of a command on the shell, this will repeat the last command (see 'HISTORY EXPANSION' in the bash manpage for more information on that).
Solution 2:
Command history is generally stored on per-user basis in the .bash_history
file in your home directory. Means, every user has its own set of commands he has executed.
When multiple terminal sessions are open they may show you different commands when pressing the arrow key, but when you will close all the terminal windows the history from different terminal session will be merged to a common ~/.bash_history
file.