erasedups option will remove duplicated lines limited by this two conditions:
- The lines will be erased from the list in memory.
- Only when a new command is going to be added to the list.
The list in memory is the output of
The whole list "in memory" will be written to file with
history -w or when bash is closed (if histappend is not set).
So, if the list in memory is:
6 export HISTCONTROL=ignoreboth:erasedups
It will become:
4 export HISTCONTROL=ignoreboth:erasedups
All cmd1 commands (except the one being appended) are removed.
cmd2 is executed, all repeats of
cmd2 are also removed (also
2 export HISTCONTROL=ignoreboth:erasedups
But even now, the file
~/.bash_history has not been modified. It still contains the list of commands from a previous session. Using grep on the file may show many duplicates (dups), including the commands just used (cmd1 and cmd2). A grep will only work correctly on the memory list:
$ history | grep cmd1
Once the list gets written to file (history -w) is it correct that only one instance of each command line used in the session.will be found with grep.
You can force an update of the disk file every time with:
$ PROMPT_COMMAND='history -w'