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_history
really does delete~/.bash_history
....but (unless you take steps to prevent it, like clearing the in-memory history by runninghistory -c
just before you logout or settingHISTFILE=/dev/null
or justunset
ing it) bash will just save its current history again when it exits. BTW, theHISTSIZE
env var tells bash how many lines of history to keep in memory, andHISTFILESIZE
tells bash the maximum number of history lines to save. both of these can be set in, e.g., your~/.bashrc
. PS: your cat deserves a 2nd reward for teaching you a valuable lesson :)