If I add export HISTCONTROL=ignorespace in .bashrc, bash won't record any commands which have whitespace before them into history. But I do not understand under what situations it will be useful. Can anyone give some examples?

up vote 32 down vote accepted

If your commands contain passwords or other sensitive informations

  • 4
    @acgtyrant then you never entered a command with a password. The idea is if you provide a password on the commandline just put a space before the command and it won't get recorded to the HISTFILE – Ulrich Dangel Apr 27 '13 at 10:57
  • 3
    mysql commands can accept the password of the user that you're connect to the database with, there are too many to list here. The point @Ulrich Dangel made is spot on. If you're typing commands with passwords, don't leave them in the history. – slm Apr 27 '13 at 11:34
  • 5
    I'll also add that when you're and administrator you often don't want the history on because if an attacker were to get into the system you're leaving him a trail of where things are on the box and what types of commands are typically run on the box. – slm Apr 27 '13 at 11:35
  • 1
    If you don't have any commands with sensitive information, then you're not the target audience for that feature. Not every feature in a program is used by every user. (That's one reason why programs have "feature creep": everyone uses a dozen features, but a different dozen, and wonders what all the other useless cruft is for.) – Kaz Apr 28 '13 at 4:22
  • 1
    Keep in mind that command-line arguments are often visible in ps, or by looking in /proc. Some systems make the environment visible to other users as well. A mode 0700 file on a tmpfs, OTOH, doesn't have these problems. – derobert Apr 29 '13 at 15:13

Another usage is for commands that you don't want to accidentally repeat, such as rm -rf *. I make extensive use of history and occasionally hit Enter accidentally when the command I've retrieved from history is not the one I was looking for. Granted, the real solution is to always read commands carefully before executing them. But being a bit clumbsy, I prefer to also keep particularly destructive commands out of my history as an extra precaution.

  • 14
    I'd add that I found it very convenient to further ignore some dangerous commands even if I forget to include a space: HISTIGNORE=" *:rm -f*:rm -r*:*--force*". This prevents rm -f and rm -r from being saved into history, as well as anything that contained --force. – Petr Pudlák Apr 27 '13 at 18:45
  • This is the/a real solution. Don't leave knives around, saying the real solution is to not poke yourself with them. As the old proverb goes “you can't un-wee in the river” — meaning don't clean the river, instead stop dumping rubbish into it. – ctrl-alt-delor Jun 16 '14 at 13:31

A former coworker of mine did this with most cd and ls commands, to record only the "useful" commands.

  • 3
    I almost never run nethack at work without doing this... (or top, or man...) – lotsoffreetime Apr 27 '13 at 20:57
  • Actually, someone can add export HISTCONTROL=ingoredups in .bashrc to tell bash not to store duplicates so make history more clear. You can read this article – acgtyrant Apr 28 '13 at 12:01

Data privacy. The moment law enforcement breaks down your door, you may not want them to find residues of

  • where you wget the latest pron^Wwarez from
  • what movies you recently ripped and fed to a torrent
  • passwords passed via arguments to encryption/decryption programs

Seriously, it's probably the equivalent to a strict privacy setting in your browser, stopping it from recording surf history.

If you version control .bash_history it's a useful way to mark certain commands as "special". Combined with history-search-*, it's a way to press simply Space+m+Up+Enter to run make --directory ~/dev/tilde clean and Space+e+Up+Enter to run editor ~/.bash_history, both of which I use for maintenance of the Bash history file.

protected by Michael Mrozek Apr 27 '13 at 19:56

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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