Can you prevent a team from going into the command history of the bash shell?

Is there a way to prevent adding a command to the bash shell command history?

I would like to be able to prevent some โ€œdangerousโ€ commands from adding to the history, for example, โ€œ rm -rf ~/some/dir โ€ so that it is not accessible to me by pressing the up arrow to reach the previous commands. Thus, it would be impossible to accidentally repeat one of these commands.

The reason I ask is because I repeatedly use the up arrow to access previous commands in shell history and often find myself getting into what I thought was the right team, only to understand that I was going to do something stupid / annoying / dangerous. I don't like the idea of rm , etc., floating in my shell story, waiting for me to step on them!

(Note: I know that you can customize templates in HISTIGNORE, but what would be nice is that you can apply based on each command, which will be a good habit. If there is no smart way to achieve this using HISTIGNORE, which I missed?)

+47
linux unix bash shell
Mar 12 '09 at 20:43
source share
2 answers

In newer Bash versions, you can simply add a space at the beginning of your command. :) If it doesnโ€™t work by default, add [\ t] * to HISTIGNORE. (As mentioned in the comments. Thanks)

+56
Mar 12 '09 at 20:47
source share

Add ignorespace to the HISTCONTROL environment variable . Then any command line starting with a space will not be entered into your story.

+37
Apr 21 2018-11-21T00:
source share



All Articles