Created
March 16, 2018 00:03
-
-
Save sinewalker/1a628deaa26fbf3b9909a8f182fc6fdc to your computer and use it in GitHub Desktop.
Delete last command from shell history, AND the fact that you deleted it, without HISTCONTROL="ignorespace" having been set
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| history -d $((${HISTCMD}-1));history -d $((${HISTCMD}-1)) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So, you're on a server with shared Unix accounts, and you accidentally enter a command with a secret in it (a password, say). Whoops!
Then you realize your gaff, haven't got my handy alias in this shell's environment; and you need to remove it from the shell history immediately. You do this:
Phew!
Oh, but now someone looking in the history will see that and wonder "What was deleted?". To avoid that, if you've set
HISTCONTROL="ignorespace"then starting your commands with a space automatically prevents that command being written to history.You could have done this in your original gaff too, btw, if you knew you were having to enter a secret.
(note the space at the front).
Anyway, suppose the
HISTCONTROLisn't set? Or you're not allowed to by Policy? What then?Delete the deletion too, but do it in a single line: