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

Meta dot in bash

“Meta dot” or Alt+. is a really useful bash shortcut key that I’ve come to appreciate lately. It brings up the last command-line argument of the last command that you used (sort of like !$ but less of a gamble) and you can hit it repeatedly to cycle through previous command-line args. Super useful. Try it.