Skip to content

Instantly share code, notes, and snippets.

@bugre
Last active March 2, 2022 00:42
Show Gist options
  • Save bugre/c8050dc34810ea7b1d4dba92f40bb9e0 to your computer and use it in GitHub Desktop.
Save bugre/c8050dc34810ea7b1d4dba92f40bb9e0 to your computer and use it in GitHub Desktop.
Bash history deduplicate / simplify / cleanup
## ATTENTION: Complete purges history.. make a backup if you want..
# Clear bash history file and loaded history.
> ~/.bash_history && history -c
## deduplicate
## add to ~/.bashrc && ~/.bash_profile
HISTCONTROL=ignoreboth:erasedups
HISTCONTROL=ignoreboth:erasedups
HISTSIZE=50000
HISTFILESIZE=100000
HISTTIMEFORMAT="%F %T "
shopt -s histappend
## deduplicate a history file that was not previusly deduped.
## clean / dedub / reload / write
tac ~/.bash_history | awk '!x[$0]++' | tac >hist1
> ~/.bash_history && history -c
history -r ./hist1
history -w
## another option,
shopt -s histappend
export HISTCONTROL=ignoreboth:erasedups
export UPDATE_HIST="history -n; history -w; history -c; history -r"
tac ~/.bash_history | awk '!x[$0]++' | tac /tmp/tmphist; mv -v /tmp/tmphist ~/.bash_history
rm /tmp/tmpfile
## check this post: https://antofthy.gitlab.io/software/history_merge.bash.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment