Macos – Execute a terminal command without saving it to .bash_history on OS X

bashcommand linehistorymacosterminal

This site says that on Linux you can add a space before a terminal command to keep it out of .bash_history.

This does not seem to work for Mac OS X. Does anyone know of a way to execute a single command on the Terminal without saving it to history?

I don't want to clear the history.

enter image description here

Best Answer

Add the following line to ~/.bashrc

export HISTCONTROL=ignorespace

Then source ~/.bashrc to refresh the settings

This should enable that feature in bash. If it doesn't work, you might have to add it to ~/.bash_profile instead of ~/.bashrc since OS X loads them a bit differently than linux I think.