How do I keep my bash history across sessions?

Which history? bash-history? If you're losing bash history and you have multiple sessions at a time, it's because each session is overwriting the other sessions' history.

You probably want to tell bash to not overwrite the history each time, but rather to append to it. You can do this by modifying your .bashrc to run shopt -s histappend.

You can also increase the size of your history file by exporting HISTSIZE to be a large-ish number (it's in bytes, so 100000 should be plenty).


I was suffering from the same problem - but my .bashrc file already had the shopt -s histappend and correct HISTFILE, HISTSIZE, HISTFILESIZE.

For me the problem was that my .bash_history file was owned by root rather than my username, so my user could never save to that file on exit.


Look up the environment variables HISTFILE, HISTSIZE, HISTFILESIZE.