Do a command but skip recording it in the bash command history

_cd ~/nsfw; mplayer midget_donkey.mpeg
Note the extra space before the command (I had to put it as an underscore since the website eats up preceding spaces). That's all it takes. Now if you check your history with "$ history", it wont show up.

By: Kirbe
2009-02-16 17:19:40

These Might Interest You

  • Bash history commands are those that begin with the character ! (eg. the most popular 'sudo !!' Explained here => By default bash immediately executes the history command. Setting this shell option will make bash first allow you to verify/edit an history command before executing it. To set this option permanently, put this command in ~/.profile or ~/.bashrc file. To unset this option issue following command. shopt -u histverify Show Sample Output

    shopt -s histverify
    b_t · 2011-10-27 00:33:34 0
  • "What it actually shows is going to be dependent on the commands you've previously entered. When you do this, bash looks for the last command that you entered that contains the substring "ls", in my case that was "lsof ...". If the command that bash finds is what you're looking for, just hit Enter to execute it. You can also edit the command to suit your current needs before executing it (use the left and right arrow keys to move through it). If you're looking for a different command, hit Ctrl+R again to find a matching command further back in the command history. You can also continue to type a longer substring to refine the search, since searching is incremental. Note that the substring you enter is searched for throughout the command, not just at the beginning of the command." - Show Sample Output

    moollaza · 2012-04-15 16:42:32 0
  • eh stands for Edit History . Frequently, I'll mistype a command, and then step back through my history and correct the command. As a result, both the correct and incorrect commands are in my history file. I wanted a simple way to remove the incorrect command so I don't run it by mistake. . When running this function, first the ~/bash_history file is updated, then you edit the file in vi, and then the saved history file is loaded back into memory for current usage. . while in vi, remember that `Shift-G` sends you to the bottom of the file, and `dd` removes a line. . this command is different than bash built-in `fc` because it does not run the command after editing.

    eh () { history -a ; vi ~/.bash_history ; history -r ; }
    unixmonkey8121 · 2011-03-23 18:00:20 5
  • Use this if you want to add command to your bash history, but you do not necessarily want to execute it now or ever.

    history -s command
    billymoon · 2012-01-04 13:01:48 0

What Others Think

This doesn't seem to work in Centos 5 [root@centos5 /]# cd /home [root@centos5 home]# cd / [root@centos5 /]# history|tail -n 3 1018 cd /home 1019 cd / 1020 history|tail -n 3 [root@centos5 /]#
unixmonkey1114 · 487 weeks and 1 day ago
(btw, the extra space is in just doesn't show up in these comments)
unixmonkey1114 · 487 weeks and 1 day ago
Doesn't work in Fedora 10.
mariusz · 487 weeks and 1 day ago
This works with Opensuse 11 and midget_donkey rocks!!!
Williebee · 487 weeks and 1 day ago
Works in Ubuntu 8.10. Upon checking the bash man page, you need the environment variable HISTCONTROL=ignoreboth or =ignorespace. My bad for not noting this. Also you can have more control by using HISTIGNORE
Kirbe · 487 weeks and 1 day ago
other (possibly helpful) info at this duplicate:
sudopeople · 481 weeks and 5 days 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? 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.


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: