Environment & Shell Customization (Aliases/Functions/.Bashrc)
Stop letting your bash history vanish into thin air
🧩 The Challenge
You finally craft the perfect monster command to fix a production fire, only to find it missing from your history because you had two terminal windows open at the same time. I have spent way too much time hunting through partial logs because bash keeps overwriting the file instead of appending.
💡 The Fix
Flip the switch in your bashrc to force every command to append to the file immediately instead of waiting for the session to close. It keeps all your shell sessions in sync, so your history actually stays useful.
shopt -s histappend
PROMPT_COMMAND='history -a; history -c; history -r'
⚙️ Why It Works
By setting the prompt command to dump the current buffer to the file and reload it every single time you hit enter, you ensure no commands get lost when you close that second window. It effectively turns your scattered history files into one persistent, shared command stream.
🚀 Pro-Tip: Add HISTCONTROL=ignoredups:erasedups to your environment too, so you don’t have to scroll past thirty identical ‘ls’ commands just to find that one specific config edit.
Linux Tips & Tricks | © ngelinux.com | 10/17/2026
