18

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?

5 Answers 5

32

If your commands contain passwords or other sensitive informations

10
  • 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 Commented Apr 27, 2013 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. Commented Apr 27, 2013 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. Commented Apr 27, 2013 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.) Commented Apr 28, 2013 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. Commented Apr 29, 2013 at 15:13
26

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.

2
  • 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. Commented Apr 27, 2013 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. Commented Jun 16, 2014 at 13:31
6

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

2
  • 3
    I almost never run nethack at work without doing this... (or top, or man...) Commented Apr 27, 2013 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 Commented Apr 28, 2013 at 12:01
2

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.

0

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.