Execute a command without saving it in the history

<space>command
Prepending one or more spaces to your command won't be saved in history. Useful for pr0n or passwords on the commandline. Tested on BASH.
Sample Output
$ echo this goes to history
this goes to history

$   echo this wont go to history
this wont go to history

$ history
    1  echo this goes to history
    2  history

414
By: eaZy
2009-03-17 16:25:29

5 Alternatives + Submit Alt

What Others Think

depends on the variable HISTCONTROL (must be ignoreboth to work)
albanichou · 487 weeks and 2 days ago
You use the command line for pr0n?! lolz
zombiedeity · 487 weeks and 2 days ago
hmmm... 45(1 pr0n?
IMissDos · 487 weeks and 2 days ago
From man bash: HISTCONTROL A colon-separated list of values controlling how commands are saved on the history list. If the list of values includes ignorespace, lines which begin with a space character are not saved in the history list. A value of ignoredups causes lines matching the previous history entry to not be saved. A value of ignoreboth is shorthand for ignorespace and ignoredups. A value of erasedups causes all previous lines matching the current line to be removed from the history list before that line is saved. Any value not in the above list is ignored. If HISTCONTROL is unset, or does not include a valid value, all lines read by the shell parser are saved on the history list, subject to the value of HISTIGNORE. The second and subsequent lines of a multi-line compound command are not tested, and are added to the history regardless of the value of HISTCONTROL.
Malkavian · 487 weeks and 2 days ago
I wouldn't rely on this 'feature' ;) -- see other comments about HISTCONTROL in addition to reading the manual for bash!
alexandersafir · 487 weeks and 2 days ago
In zsh you can do "fc -p" to switch to a new history (and make $HISTFILE empty) and "fc -P" to switch back to the last one.
cran · 487 weeks and 2 days ago
you have to put: export HISTIGNORE="[ \t]*" in ~/.bashrc for this to work. if you don't have .bashrc in in ~/ just make your own
genofunk · 487 weeks and 1 day ago
this looks like a bug in bash...if you don't alter HISTCONTROL of course.
wwoollff · 485 weeks and 2 days ago
Use kill to exit the shell instead of exit or logout: kill -9 $$
vutcovici · 484 weeks and 6 days ago
ironically export HISTIGNORE="[ \t]*" or echo export HISTIGNORE="[ \t]*" >> .bashrc will appear in the history :) You should do <space> history -d N Where N is the postion export HISTIGNORE="[ \t]*"
funyotros · 454 weeks and 2 days ago
an easier way to do this in zsh is to add "setopt HIST_IGNORE_SPACE" to your .zshrc it'll then behave like this command should, but keep the space'd command in history till you enter another one (from man zshoptions)
awh · 322 weeks and 1 day ago
export HISTCONTROL=ignorespace worked for me. Testet on Centos 5
wahallah · 293 weeks and 4 days ago
IBM AIX's ksh supports it too, but as with CentOS, you have to export HISTCONTROL=ignorespace.
RAKK · 252 weeks ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: