Stop bash history from overwriting your commands when you have multiple tabs open
Environment & Shell Customization (Aliases/Functions/.Bashrc)
Stop bash history from overwriting your commands when you have multiple tabs open
🧩 The Challenge
You ever run a killer command in one window, switch over to another to check something, and then lose your masterpiece to history truncation? It’s enough to make you want to throw your monitor out the window when you’re trying to remember that complex regex you nailed ten minutes ago.
💡 The Fix
You need to tell the shell to append new entries to the history file immediately instead of overwriting the whole thing whenever you exit a session. It’s a dead simple setting that saves you from yourself.
shopt -s histappend
PROMPT_COMMAND="history -a; $PROMPT_COMMAND"
⚙️ Why It Works
Setting histappend keeps the shell from nuking your session logs, and forcing history -a every time you get a prompt means the file stays synced across every terminal window you have open.
🚀 Pro-Tip: Toss an export HISTSIZE=10000 and export HISTFILESIZE=10000 in there too so you don’t lose the older stuff as quickly.
Linux Tips & Tricks | © ngelinux.com | 8/15/2026
