Bash – Why does bash still keep duplicate lines with erasedups

bashcommand history

I have the following line in my ~/.bashrc

export HISTCONTROL=ignoreboth:erasedups

However whenever I run somecommand it keeps adding the duplicated command into .bash_history like this

grep -w somecommand ~/.bash_history
somecommand
somecommand abc xyz
somecommand 123
somecommand
...

Why is this and how to prevent it?

Best Answer

According to man bash:

A value of ignoredups causes lines matching the previous history entry to not be saved.

If you run somecommand twice in a row with no arguments, you should see only one consecutive entry.

Likewise if you run somecommand 123 twice in a row, it will only be added to the history once.

The commands in your list show no consecutive duplicates, so this feature is working as intended.

Related Question