There’s been a number of times I’ve wanted to not include some commands that I type into bash from being added to bash_history

The most convenient is to start a subshell by typing in bash again. This ensures that the commands in the subshell don’t get added to the history.

There are additional ways of achieving this as well.

Don’t log all the commands typed already in the current shell

So, I’ve typed a bunch of commands and now I realize that these shouldn’t get saved when I log out of the session. To do this I type unset HISTFILE before I log out.

Don’t log the current command

If I just don’t want the current command to be logged into history, I can just add a space before the command.

In case it doesn’t work, the following in .bashrc should ensure that it does!

export HITCONTROL=ignoreboth

Don’t log the next set of commands

I log into a system via ssh and I don’t want the commands logged. The way to do this is to open a subshell with bash command.

This ensures that the commands typed in the subshell don’t get logged at all.

This method is quite convenient as I type a bunch of commands together and I can always exit the subshell to get logging going again.

Hat tip to – How to hide your Bash Command History