Unifying Bash History

A question came up in our Linux User Group IRC channel about the seemingly random mess that is your bash command history. As I googled around for the answer to what was going on I came across this snippet of pure joy.

shopt -s histappend
export PROMPT_COMMAND="history -a; history -n; $PROMPT_COMMAND"

If you add those 2 lines to your .bashrc what you get is a unified bash history. All commands from all terminals get saved in real time and are made available to all other terminals.

It’s pretty great, though it does make you realize that some times you really did rely on the old behavior. The up key no longer does exactly what you are used to.