Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
    
adding a ` ` (space) before a terminal command will not keep it out of the history –  warren Aug 18 '11 at 16:20
2  
@warren No, it does. You just have to enable the feature in bash. –  firebat Aug 18 '11 at 16:33
    
@firebat - right: but since it's something you have to enable, it may or may not work everywhere :) –  warren Aug 18 '11 at 16:35

2 Answers 2

up vote 14 down vote accepted

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.

share|improve this answer
    
How can I use two options with that? I want to use export HISTCONTROL=erasedups,ignorespace but I think that syntax does not work... –  cwd Aug 18 '11 at 16:33
2  
export HISTCONTROL=erasedups:ignorespace –  firebat Aug 18 '11 at 16:34
    
perfect, thanks! –  cwd Aug 18 '11 at 16:35
2  
But i think it's actually export HISTCONTROL=ignoredups:ignorespace –  firebat Aug 18 '11 at 16:35
3  
The "ignoredups" setting ignores repeated lines. Typing "ls" twenty times in a row only ends up with one of them in history. However, typing "ls" and then "ps" and then "ls" again will store "ls" and "ps" every time - unless you have bash 3 and set "erasedups". If that's set, no duplicates get entered in bash history at all. - cyberciti.biz/faq/bash-for-loop-array –  cwd Aug 18 '11 at 18:39

If you're not concerned about keeping the session active, this may work:

kill -9 $$

It will kill the current session instead of logging-out, which [theoretically] means your history will not be saved.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.