It’s probably not a good idea to completely turn off bash history, one of the reasons bash history exists as a reference to mistakes or useful past commands you can’t recall. But there are also legitimate reasons who don’t want to log some bash commands for security or privacy reasons. Here are 3 ways you can temporarily turn off bash history logging:
unset HISTFILEThis will prevent all commands run in the current login session from getting saved to the
.bash_historyfile when you logout. This will reset all commands you ran earlier in session until you logout. There is also no way to verify if it’s working, as you can still use UP key to go to your previous commands. The only way to verify is to logout and login back and check your bash history.
- Perhaps the best solution, if you want to selectively ignore specific bach commands being logged into bash_history is to type a space before a command. This should be on by default and work on all bash sessions but ff it does’nt work, add the line
export HISTCONTROL=ignorebothto your .bashrc file. In your future sessions commands with space will not be logged.
- Perhaps the easiest is to type
shand it will start a subshell. Any commands typed in the subshell, won’t be logged into your history, untill you exit from the subshell. Anyone checking your bash history file will only be able to see that you ran sh, but not see what you ran after that.
There are several other clever ways to achieve this but the above mentioned tips are the most common ways of doing this.