Skip to content

Instantly share code, notes, and snippets.

@keinwort
Last active September 18, 2017 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keinwort/6122b4f3563804b3893a2ce5f20c9182 to your computer and use it in GitHub Desktop.
Save keinwort/6122b4f3563804b3893a2ce5f20c9182 to your computer and use it in GitHub Desktop.
remove duplicate lines of current bash_history #bash #sh #macOS #linux #bash_history
#!/usr/bin/env bash
## https://superuser.com/questions/722461/how-can-you-remove-duplicates-from-bash-history
## It is possible to remove duplicated lines which are already in .bash_history by running
echo bash_history - remove duplicated lines
echo --------------------------------------
echo first back it up
date_now=$(date +"%Y-%m-%d-%H%M%S")
cp ~/.bash_history ~/bash_history.old_$date_now
echo removing duplicate lines
nl ~/.bash_history | sort -k 2 -k 1,1nr| uniq -f 1 | sort -n | cut -f 2 > ~/unduped_history
echo copying over old history file
cp ~/unduped_history ~/.bash_history
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment