Execute a command without keeping it in history [closed]

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., to file %HOME/.bashrc.

     export HISTCONTROL=ignorespace
    

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

Leave a Comment