why deleting bash history is not enough?

In some cases (some bash versions), doing a:

$ history -c; history -w

Or simply

$ history -cw

Will clear history in memory (up and down arrow will have no commands to list) and then write that to the $HISTFILE file (if the $HISTFILE gets truncated by the running bash instance).

Sometimes bash choose to not truncate the $HISTFILE file even with histappend option unset and $HISFILEZIZE set to 0.

In such cases, the nuke option always works:

history -c; >$HISTFILE

That clear the history list of commands recorded in memory and all commands previously recorded to file. That will ensure that the running shell has no recorded history either in memory or disk, however, other running instances of bash (where history is active) may have a full copy of commands read from $HISTFILE when bash was started (or when a history -r is executed).

If it is also required that nothing else (no new commands) of the present session would be written to the history file, then, unset HISTFILE will prevent any such logging.


bash has a session history in memory which is written to file if the shell variable HISTFILE is set to a filename when bash exits.

If you delete the file pointed to by HISTFILE, unset that variable, and exit bash, then that shell session will not leave any persistent history.

Failing to unset the HISTFILE variable but deleting the file would just empty the persistent history, but the current session's history would be saved when the shell exits.

Tags:

Linux

Bash

Bashrc