Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

This question already has an answer here:

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?

share|improve this question
    
askubuntu.com/questions/15926/… –  Rinzwind May 15 '13 at 10:23
    
I saw that question, but it does not seems to be the same since I'm already doing what it suggests –  Psicofrenia May 15 '13 at 10:24
    
@Psicofrenia It is export HISTCONTROL=ignoreboth:erasedups, or you write export HISTCONTROL=ignoreboth that's incorrect. –  Radu Rădeanu May 15 '13 at 10:26
    
Sorry but ... export HISTCONTROL=ignoreboth and export HISTCONTROL=ignoreboth:erasedups are 2 diff. things –  Rinzwind May 15 '13 at 10:26
1  
From man bash: "A value of erasedups causes all previous lines matching the current line to be removed from the history list before that line is saved." Did you test erasedups? –  Eric Carvalho May 15 '13 at 11:14
show 4 more comments

marked as duplicate by Rinzwind, Mitch, raaz, bcbc, user68186 May 15 '13 at 19:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers

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.

share|improve this answer
    
Great one-liners! Thanks. In my case, "temp_file > ~/.bash_history" didn't work, but "cat temp_file > ~/.bash_history". Also, you forgot a last "rm temp_file" :) –  Elena Dec 31 '13 at 18:09
add comment

"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.

share|improve this answer
    
I changed to export HISTCONTROL=erasedups, opened a new tab, and used an inexistent command kaka. Cat the .bash_history before kaka was kaka kaka kaka, since I tried it 3 times before the change, after it became kaka kaka kaka kada –  Psicofrenia May 15 '13 at 10:46
    
Btw, if I echo HISTCONTROL I get erasedups –  Psicofrenia May 15 '13 at 10:49
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.