Disable repeated items in bash history

bashcommand historyfedora-19

Bash in Fedora 19 is really annoying me. Say I run a command:

echo "Hello"

Then I run another command:

echo "World"

Now I run the last command (echo "World") again N times by pressing up on my keyboard, followed by enter. (Typical usage.)

The problem is that every one of those echo "World" commands is inserted into the history, even though they are identical. I want to simply press up twice and get to echo "Hello". Instead, I must press up N+1 times.

Why is this broken? How do I fix it?

Best Answer

To uniqely record every new command is tricky. First you need to add to ~/.profile or similar:

HISTCONTROL=erasedups
PROMPT_COMMAND='history -w'

Then you need to add to ~/.bash_logout:

history -a
history -w
Related Question