1

What's the easiest way to prevent dangerous commands matching a pattern (like rm) from going into the Bash command history? I'd like to keep them away from the history of the current session, not just from the .bash_history file.

Lassi
  • 831
  • 6
  • 15

1 Answers1

3

OK, seems there have been a few somewhat similar questions. The answer is to use:

export HISTIGNORE="rm*"

(It seems to be using glob syntax, and multiple patterns can be given by separating with colons :)

Another way is to set:

export HISTCONTROL=ignorespace

which will cause Bash to keep all commands starting with a space out of the history. So if you can get into the habit of typing space-rm-whatever this will work fine.

To keep both space-commands and duplicate commands out of the history, you can do:

export HISTCONTROL=ignoreboth

It's also possible to use both HISTIGNORE and HISTCONTROL.

Lassi
  • 831
  • 6
  • 15