Skip to content

Did you know?

Starting a command with a space keeps it out of your Bash history.

Works by default on Ubuntu and Debian, where HISTCONTROL=ignoreboth.

  • Shell & terminal
  • Applies to Ubuntu, Debian (default ~/.bashrc)
  • Last checked

Explained

Sometimes you run a command you don’t want saved in ~/.bash_history, such as one that contains a token. If HISTCONTROL includes ignorespace, Bash doesn’t record any command that starts with a space.

echo $HISTCONTROL
ignoreboth

ignoreboth means ignorespace plus ignoredups (don’t store the same command twice in a row). It is set in the default ~/.bashrc on Ubuntu and Debian. On other distributions, add it yourself:

echo 'export HISTCONTROL=ignoreboth' >> ~/.bashrc

Keep in mind that this only hides the command from your history file. While it runs, the full command line, including any password, is visible to other users through ps. For real secrets, use environment files, password prompts or a secrets manager rather than command-line arguments.

Learn more

← All tech tips · Suggest a fix

Back to top