Skip to main content
6 of 6
Added regex
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

We can eliminate duplicate lines without sorting the file by using the awk command in the following syntax.

awk '!seen[$0]++' source.txt > target.txt 

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

Also in nano using regex:

Press Ctrl + \ Enter your search string return Enter your replacement string return Press A to replace all instances

in vim :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