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 replacingawk '! x[$0]++' $@withtac $@ | 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
Press
Ctrl + \Enter your search stringreturnEnter your replacement stringreturnPressAto 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