Don’t lose history in bash

I don’t think I’ve relied too heavily on bash’s history feature in the past, because often what I needed to recall wasn’t there. The reason why is that if you have multiple bash shells, by default each one rewrites the entire .bash_history file when it exits, which means that you keep losing stuff. It turns out that there is a very easy way to fix this – add these lines to your bash startup files:


shopt -s histappend
PROMPT_COMMAND='history -a'

I have no idea why this is not the default behavior!

This and other bash tips here

Leave a Reply

Your email address will not be published. Required fields are marked *