4

Supposedly, adding export HISTCONTROL=ignoreboth to .bashrc would do the trick, but what I see in practice is there still exists duplicated lines in my .bash_history file.

You can see my .bashrc below.

export HISTFILESIZE=100000
export HISTSIZE=100000 
export HISTIGNORE="ls*:rm*:cd*:CD*:ps*:exit*:reset*:clear*:synaptic*:mkdir*:cat*"
export HISTCONTROL=ignoreboth
shopt -s histappend
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"

Does anybody know why I'm still getting duplicated lines?

Radu Rădeanu
  • 174,089
  • 51
  • 332
  • 407

2 Answers2

4

HISTCONTROL only affects new hist lines.
What I think the author what is a way to edit the existing hist file.

nl ~/.bash_history | sort -k 2 | uniq -f 1 | sort -n | cut -f 2 > temp_file
followed by
temp_file > ~/.bash_history

This should preserve line order, while removing dups from the existing hist file.
May leave behind ghost time-stamps, if you have turned on time-stamps.
If you have that issue, comment, and I'll whip up a second clean up for those.

demure
  • 2,322
0

"erasedups" should do the trick, did you source .bashrc after your change?

Can you please echo $HISTCONTROL and tell us the output? Also: be sure you actually want to do that on .bashrc and not in .bash_profile instead...

Basically, what I'm suspecting is that you simply don't have HISTCONTROL on your environment.