Exit bash without writing anything
This is hacky and aggressive. But it’s a fun way to end an espionage session.
Clears the history of the current session, even this command itself
Disables history saving
Reloads history from disk
Executes a commande without including it in history
Deletes your password (a command, etc.) from your history
If all you are concerned about is getting rid of a single entry, you can use the previous example creatively. Use
history
to find the number of the entry to delete. Then delete it by number. For example…I hope I don’t have to tell you this, but just in case: Don’t grep history for your password. If you “really do” need to search history, do
history | LESSHISTFILE=/dev/null less
, and explicitly do a/
search.If you are really embarrassed and want there to be no record of you deleting something from history, you can combined this concept with the last.
Or to also get rid of the original mistake…
Notice that you have to cycle over the entry numbers in descending order because each call to
history -d
pops the entry out of the list and all subsequent entries’ numbers decrease by 1. Also, you have to double quote the subshell becausehistory 1
returns not just the number, but also the command and its arguments, and each would get a separate cycle in thefor
loop. But at this point this is turning into abash
lesson and I’ll stop.
#shell #bash