Skip to main content
2 of 6
added 36 characters in body
Anthon
  • 81.4k
  • 42
  • 174
  • 228

This is what I came up with and I am happy with it so far...

alias hfix='history -n && history | sort -k2 | uniq -f1 | sort -n | cut -c8- > ~/.tmp$$ && history -c && history -r ~/.tmp$$ && history -w && rm ~/.tmp$$'  
HISTCONTROL=ignoreboth:erasedups  
shopt -s histappend  
HISTSIZE=1000  
HISTFILESIZE=2000  
export HISTIGNORE="&:[^ \t]*"  
PROMPT_COMMAND="hfix; $PROMPT_COMMAND" 

NOTES:

  • Yes, it is complicated... but, it removes all duplicates and yet preserves chronology within each terminal!
  • my HISTIGNORE ignores all commands that don't have arguments. This may not be desireable by some folks and can be left out.