put these line on your .bashrc
:
...
alias dedup='history -n; history -w; history -c; history -r;'
# https://superuser.com/a/664061/1867794
# Eternal bash history.
# ---------------------
# Undocumented feature which sets the size to "unlimited".
# https://stackoverflow.com/questions/9457233/unlimited-bash-history
HISTFILESIZE=
HISTSIZE=
HISTTIMEFORMAT="[%F %T] "
# Change the file location because certain bash sessions truncate .bash_history file upon close.
# http://superuser.com/questions/575479/bash-history-truncated-to-500-lines-on-each-login
HISTFILE=~/.bash_eternal_history
# https://askubuntu.com/a/667787
HISTCONTROL=ignoredups:ignorespace:erasedups
shopt -s histappend
shopt -s cmdhist
function historymerge {
dedup
}
trap historymerge EXIT
PROMPT_COMMAND="history -a; $PROMPT_COMMAND"
type set +o history
on the shell to disable the history feature
type trap | awk '{ print $NF }'
to list active trap
type trap - EXIT
to unset the pre-defined trap from .bashrc
type history | less
to view the history file
The problem occurs when: you opened two or more terminal, editing history file in the first terminal and working for other stuff in other terminal
The changes made in the history file will not applied if the dedup
is executed (which will be executed soon as EXIT by trap
triggered) unless you disable the trap.
But if you disable it, then the history file stored in the memory on each terminal session will ignore any duplicate entries and not removing it.
keep in mind that de-duplicate entries feature only works if in the current shell session you've already type the same command at least once.
every thing has its own history