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?
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.
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.