Skip to content

Instantly share code, notes, and snippets.

@avinash2
Forked from rawsyntax/bash-history.sh
Created August 22, 2014 12:47
Show Gist options
  • Save avinash2/67973917680f74a28063 to your computer and use it in GitHub Desktop.
Save avinash2/67973917680f74a28063 to your computer and use it in GitHub Desktop.
# say we start with an empty bash command history
bash-3.2$ history
1 history
# enter a command that requires a password
bash-3.2$ sudo rm -i some_file
Password:
# accidentally ^C and type your password
# into the prompt and hit enter
bash-3.2$ secret_password
bash: secret_password: command not found
# your password is now there for all to
# see in your bash history
bash-3.2$ history
1 history
2 sudo rm -i some_file
3 secret_password
4 history
# first option to fix it, delete the numbered entry from
# history and write to your ~/.bash_history file
bash-3.2$ history -d 3
bash-3.2$ history -w
# entry 3 will be removed entirely from your command history
bash-3.2$ history
1 history
2 sudo rm -i some_file
3 history
4 history -d 3
5 history -w
6 history
# the second option is to clear the entire history
# and write the changes to disk
bash-3.2$ history -c
bash-3.2$ history -w
# it's now pretty obvious that your history has been
# scrubbed clean, but at least your password is history!
bash-3.2$ history
1 history -w
2 history
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment