Bash History Tricks
In this bash basics HakTip, we're covering bash history tricks.
In the world of Linux, and computers in general, there's more than one way to skin a cat. Or so the proverb goes.
Actually, on a side note that proverb dates back to 1678 with the second edition of John Ray's collection of English proverbs. It later came to the states in Mark Twain's 1889 novel "A Connecticut Yankee in King Arthur's Court". Some have pointed out that rather than a feline the cat in question may refer to a catfish, which is usually skinned before cooking, or the gymnastics performance involving passing ones legs over their arms while hanging from a bar. Either way, I should make it clear that here at Hak5 we love cats.
Alright, now with that out of the way, our recent look into hiding passwords from Bash history spurred a flurry of feedback, including this tip from Meimi039 who wrote:
To avoid passwords in bash_history use:
Any command starting with a space wont show up in the history.
Meimi039 goes on to say:
You can also do this by setting: export HISTIGNORE=""""pass:wget:ls -ltr:"""" Commands containing 'pass' or 'wget' ... will not be added to the history...
Thanks for the tip Meimi. TheOnlyEpsilonAlpha pointed out that if a user were to gain access to your system during that session the password could be retrieved by issuing echo $password. This is true, so to work around be sure to unset the variable with the aptly-named unset command.
Metalhead noted that he used the history -c command out of force of habit when logging out of a session. The -c option clears the history. Alternatively the -d option will delete a specific history entry.
Fisurad0 points out that issuing HISTSIZE=0 will nullify the history completely.
Polokov has a really neat one. Seems if you use the arrow keys to select the previously typed command and issue the shortcut CONTROL+a, CONTROL+a then CONTROL+k it'll remove the line from the history. Neato!
And finally OverSoft points out that the .bash_history command can simply be deleted. Problem solved!