Stop your shell history from getting nuked by concurrent sessions
Environment & Shell Customization (Aliases/Functions/.Bashrc)
Stop your shell history from getting nuked by concurrent sessions
🧩 The Challenge
Everyone works with multiple tabs open, but bash usually overwrites the history file when you close a window, meaning you lose the commands you just ran in the other three terminals. It’s infuriating when you need that one complex find command you typed five minutes ago and it’s just gone into the void.
💡 The Fix
You need to tell bash to append the history in real-time instead of waiting for the session to exit. This way, every command hits the disk immediately and becomes available to your other shells.
shopt -s histappend
PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
⚙️ Why It Works
Setting the shell option for appending ensures we aren’t clobbering the file on exit, while forcing a reload of the history list after every command keeps your current session in sync with the file on disk.
🚀 Pro-Tip: Increase your HISTSIZE and HISTFILESIZE in your .bashrc to at least 10000 unless you want your history to rotate out before you remember what you did last Tuesday.
Linux Tips & Tricks | © ngelinux.com | 9/29/2026
