Automatically clear GNU Bourne-Again SHell history when you exit a login shell.
HISTFILE shell variable on login to ensure that the command history will be not saved when a shell exits.
$ echo "unset HISTFILE" | sudo tee /etc/profile.d/unset_histfile.sh
HISTSIZE shell variable to `` on login, so executed commands will not be saved in the history list.
Beware, this is very inconvenient as it will entirely disable history in a login shell. My advice is to skip this step and use the default value this time.
$ echo "HISTSIZE=0" | sudo tee /etc/profile.d/disable_histsize.sh
/etc/bash.bash_logout login shell cleanup file that will be executed when a login shell exits. Use it to clear the history list.
Do not worry, it will be executed after the
~/.bash_logoutindividual login shell cleanup file.
$ echo "history -c" | sudo tee /etc/bash.bash_logout
Notice, it will not write the emptied history list to the history file. Adding a second command to write to the history file will not work as the
HISTFILEshell variable was unset. This also means that the history list will be not initialized from the history file on startup.
~/.bash_history history file to keep things clean. Remember about other users.
You can always store the history list in a custom file. Notice, this command will append the current history list to a file.
$ HISTFILE=session_history.txt history -w
$ cat session_history.txt cat .bash_history HISTFILE=session_history.txt history -w
HISTORY section on the
bash manual page to learn more about this topic.