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.
Asked
Active
Viewed 557 times
1

Lassi
- 831
- 6
- 15
-
3Like https://unix.stackexchange.com/q/32460/117549 ? – Jeff Schaller Apr 23 '19 at 14:57
-
Thank you. I followed some links from that page and cobbled together an answer below. – Lassi Apr 23 '19 at 16:42
1 Answers
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