Execute command without keeping it in history


I want to execute some commands but don't want to store them in the command history. So that nobody will be able to search it in the .bash_history file.

Is there any way how to execute bash commands this way?

This question is tagged with linux bash unix

~ Asked on 2011-12-12 10:48:21

The Best Answer is


Start your command with a space and it won't be included in the history.

Be aware that this does require the environment variable $HISTCONTROL to be set.

  • Check that the following command returns ignorespace or ignoreboth

    #> echo $HISTCONTROL
  • To add the environment variable if missing, the following line can be added to the bash profile. E.g. %HOME/.bashrc

    export HISTCONTROL=ignorespace

After sourcing the profile again space prefixed commands will not be written to $HISTFILE

~ Answered on 2011-12-12 10:50:54


In any given Bash session, set the history file to /dev/null by typing:

export HISTFILE=/dev/null

Note that, as pointed out in the comments, this will not write any commands in that session to the history!

Just don't mess with your system administrator's hard work, please ;)

Doodad's solution is more elegant. Simply unset the variable: unset HISTFILE (thanks!)

~ Answered on 2011-12-12 10:50:55

Most Viewed Questions: