I'm working with my .bash_history file and want to identify repetitive commands for cleanup.
Here's a sample snippet:
...
#1713251479
sh lowbat.sh
#1713251495
nvim lowbat.sh
#1713252186
sh lowbat.sh
#1713253121
xclip -sel clip lowbat.sh
#1713253722
cd code/dotfiles/
#1713253766
git add mpv/
...
My goal is to:
- Sort the commands alphabetically to easily identify redundant entries.
- Review and edit the sorted list (in the
.bash_history_sortedfile) to omit unnecessary commands. - Restore the original order (sorted by timestamps) in the
.bash_history_sortedfile and finally overwrite the original.bash_historyfile with.bash_history_sortedfile.
Can this be achieved using the sort command?
EDIT: I ended up writing my own program in C language. Here's the source code, although I'm still open to other approaches.
HISTCONTROL,HISTFILESIZEandHISTIGNOREin the Bash manual. Withexport HISTCONTROL=ignoreboth, both commands starting with space and duplicates are not saved.