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
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
HISTFILEUlrich Dangel– Ulrich Dangel2013-04-27 10:57:14 +00:00Commented Apr 27, 2013 at 10:57 - 3mysql 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.2013-04-27 11:34:33 +00:00Commented Apr 27, 2013 at 11:34
- 5I'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.2013-04-27 11:35:29 +00:00Commented Apr 27, 2013 at 11:35
- 1If 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– Kaz2013-04-28 04:22:44 +00:00Commented Apr 28, 2013 at 4:22
- 1Keep 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– derobert2013-04-29 15:13:39 +00:00Commented Apr 29, 2013 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.
- 14I'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 preventsrm -fandrm -rfrom being saved into history, as well as anything that contained--force.Petr– Petr2013-04-27 18:45:56 +00:00Commented 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.ctrl-alt-delor– ctrl-alt-delor2014-06-16 13:31:21 +00:00Commented Jun 16, 2014 at 13:31
A former coworker of mine did this with most cd and ls commands, to record only the "useful" commands.
- 3I almost never run nethack at work without doing this... (or top, or man...)lotsoffreetime– lotsoffreetime2013-04-27 20:57:45 +00:00Commented Apr 27, 2013 at 20:57
-
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.