Last active
September 18, 2017 15:39
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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