I have the opposite question to this. How do I keep all commands in bash history?

In Ubuntu since quite some time now, the default for bash is to forget commands with non success exit code.

Unix user @goldilocks pointed out that maybe I am just confused by the ignoreboth directive.

set pastie

  • 3
    To me it looks like this is not the default to forget unsucessful commands in Ubuntu. What version are you using? Could you post a link to the output of the "set" command in pasebin or something so we could see what makes it delete the commands?
    – Didi Kohen
    Dec 6, 2012 at 10:25
  • @DavidKohen, added pastebin link. Dec 6, 2012 at 10:43
  • 1
    The only thing I see in relation to history deletion is the fact that it ignores duplicates and lines that start with a space. Are you sure it ignores the failed commands?
    – Didi Kohen
    Dec 6, 2012 at 10:55
  • I was quite sure, but you make me doubt myself. It's not that way for "false". I will come back to this question and update it when annoyance strikes again. Dec 6, 2012 at 12:08
  • The 'this' and 'much prefer this' lead to the same place, which is a bit confusing...
    – goldilocks
    Dec 6, 2012 at 12:27

3 Answers 3


FWIW, I use HISTFILE=~/.bash_history_$(date '+%Y%m%d_%H_%M_%S_%N').txt in my .bashrc file to make a single history file for each session, with a timestamp. That way I don't lose commands when I hit $HISTSIZE commands. history only shows me the command history for the current terminal session, but I can easily search previous bash history with grep 'what to find' .bash_history*


I think you are confused because of HISTCONTROL=ignoreboth. See here: http://www.linuxjournal.com/content/using-bash-history-more-efficiently-histcontrol


I suspect that you're not doing quite what you think you're doing. Run frobiz: , then see if that's in your history. Frobiz should normally fail - there's no such command. But it will be in your history. I suspect that you are trying something like ls *![0-9], which will fail with

ls !(*.[0-9])
base ![0-9]": event not found

The thing is; when failing like this, bash never attempts to run the command, so it doesn't get put into the history. IGNOREBOTH is irrelevant to this - it works as advertised. Try escaping the ! (which the shell is taking to refer, ironically, to a command in the history) - eg:

ls \! ...

And it will probably work as expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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