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?
If your commands contain passwords or other sensitive informations
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.
A former coworker of mine did this with most
ls commands, to record only the "useful" commands.
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?