Stop making a mess of your shell history with accidental duplicates
Environment & Shell Customization (Aliases/Functions/.Bashrc)
Stop making a mess of your shell history with accidental duplicates
🧩 The Challenge
You know that feeling when you’re mashing the up arrow to find a command you ran five minutes ago, but you have to scroll past thirty identical entries first? It drives me nuts when my history file gets cluttered with the same command I just ran because I mistyped it twice.
💡 The Fix
You can tell bash to ignore those repetitive hits by tweaking a couple of internal shell variables. It cleans up your search experience instantly and saves you from scrolling through garbage.
export HISTCONTROL=ignoreboth:erasedups
export HISTSIZE=10000
export HISTFILESIZE=20000
⚙️ Why It Works
Setting the erasedups option tells the shell to kick out the old duplicate entry whenever you run the same command again. It keeps your history clean by only holding onto the most recent version of that specific command string.
🚀 Pro-Tip: Add shopt -s histappend to your bashrc too, otherwise multiple terminal windows will just overwrite each other’s history when you close them.
Linux Tips & Tricks | © ngelinux.com | 9/28/2026
