Clear BASH history
To prevent a command from being added to the history in the first place, make sure that the environment variable HISTCONTROL
contains among its colon-separated values the valueignorespace
, for example (add e.g. to .bashrc
):
$ export HISTCONTROL=ignorespace
This will prevent any command with a leading space from being added to the history. You can then clear the history completely by running
$ history -c -w
^-- additional space character