Don't let repeated commands pollute your shell history

Originally posted on 2020-10-26

I often run a command over and over to see if it finished. I know, I probably should just use watch COMMAND instead but sometimes I forget.

If you want to avoid polluting your bash history with repeated commands it's pretty simple. Just add this line to your ~/.bashrc:

export HISTCONTROL=ignoreboth:erasedups

Then close your shell and reopen it. The next time a command is executed and your history is updated it'll make sure it doesn't add a duplicate. In my case it even went back and removed old duplicate lines.