Skip to main content
5 of 6
Added: preserving the order without sort
social
  • 325
  • 2
  • 7

Other ways to do this here as well:

https://stackoverflow.com/questions/338285/prevent-duplicates-from-being-saved-in-bash-history/7449399#7449399

Excellent answer. If you would rather preserve the chronological order (instead of the input order) for your commands, modify dedup() by replacing awk '! x[$0]++' $@ with tac $@ | awk '! x[$0]++' | tac – trusktr

https://superuser.com/questions/722461/how-can-you-remove-duplicates-from-bash-history

Also in vim text editor :sort u

If some of the suggestions including the ones above don't work immediately. After running the code I do:

history -c 

to clear the history first then restore the no duplications version over it:

cp temp.txt ~/.bash_history 
social
  • 325
  • 2
  • 7