
We’ll again switch to a new terminal (Terminal 3): $ echo "Terminal 3 here. Let’s now execute something from another terminal ( Terminal 2): $ echo "This one is from Terminal 2" We have logged on to two other terminals also, as we can verify by the output of the pstree command. bashrc file and executed the pstree command from, let’s say, Terminal 1. PROMPT_COMMAND="$history -a history -c history -r" We can now add the below entries to ~/.bashrc to solve our main problem: $ shopt -s histappend In that case, after Bash exits, the first 50 entries of the file will be lost since we had set HISTFILE to contain only 1000 latest entries. Let’s assume that the file already has 900 entries, and during our session runtime, 150 new entries are added. Here as specified in HISTSIZE, our Bash history can contain a maximum of 1000 entries. We can tweak this limit by another shell variable $HISTSIZE: $ echo $HISTSIZE

However, we should note here that there’s a limit on the maximum number of lines that can be written back to the disk. When the shell exits it writes backs the contents of memory back to disk on $HISTFILE file. During the shell session, it adds contents to the memory file.


When the Bash shell is loaded interactively on user login, it reads the contents of $HISTFILE into memory. We’ll see this in action later in the tutorial. But we can change the file path and name by setting a special shell variable $HISTFILE. bash_history file in the user’s home directory stores the sequence of commands executed on a terminal.
