Last active
November 30, 2023 02:47
-
-
Save terrywang/74d1617600dfc7c2fb4c6365c60b09db to your computer and use it in GitHub Desktop.
Bash history HISTFILE deduplication while preserving order
This file contains 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
# backup HISTFILE | |
cp ~/.bash_history{,.bak} | |
# deduplicate - deprecated | |
nl ~/.bash_history.bak | sort -k2,2 -k1,1nr | uniq -f1 | sort -k1,1n | cut -f2 > ~/.bash_history | |
# dedupelicate | |
cp ~/.bash_history{,.bak-$(date -I)} | |
tac $HISTFILE | awk '!x[$0]++' | tac | sponge $HISTFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment