I ssh into my servers using root. Sometimes when I scroll back in my history, I see a history from an earlier session, but not the last session. Why does this happen with the same user account? Is it related to the tty I am using? Bash 4
Bash – see different versions of bash history for the same user
bashcommand history
Best Answer
Every time you close a shell the contents of the history for that particular shell overwrites the history file that was written by previous ones.
The contents of a shell's history is stored in this file
$HOME/.bash_history
. It's a plain text file so you can check it out. There are numerous options to history that you can set to augment it's behavior. Take a look at the bash man page. Most of them are namedhist*
orHIST*
. Just search for them.In particular,
shopt -s histappend
makes bash append the current session's history to the history file instead of overwriting the history file.