Stop fighting with your history file when you have ten windows open
Environment & Shell Customization (Aliases/Functions/.Bashrc)
Stop fighting with your history file when you have ten windows open
🧩 The Challenge
You’ve finally tracked down that weird production bug in one shell, but when you switch to another terminal to write the fix, your history isn’t there. It’s infuriating when you just ran the perfect command two minutes ago and now it’s gone into the void.
💡 The Fix
Bash doesn’t actually write your history to the disk until you close the session by default, which is a massive headache. You can force the shell to write and append every single command as you hit enter so all your open windows stay synced.
shopt -s histappend
PROMPT_COMMAND="history -a; history -n; $PROMPT_COMMAND"
⚙️ Why It Works
Adding history -a forces the shell to append the current session’s command to the history file immediately, while history -n pulls in any new commands written by your other terminal windows. Putting this in your PROMPT_COMMAND ensures it fires automatically every time your prompt renders.
🚀 Pro-Tip: Set your HISTFILESIZE and HISTSIZE to something massive, like 50000, so you don’t lose that one command you ran six months ago.
Linux Tips & Tricks | © ngelinux.com | 9/10/2026
