Friday, January 27, 2012

Deleting an item from bash history

I was pecking away commands on the bash command line and, without paying attention, I typed in my password when I thought it was needed for a command. But looking up I saw that I was not getting a password request, but was on the command line. Aside from being thankful that I do not use a valid command for a password, I was concerned that I was leaving my password in plain text in my bash history. My home directory is encrypted, so there is little chance that someone will get access to it, but I wanted to delete it nonetheless.

To view the bash history, type


You will see something like this:

943 mvn install
944 top
945 MyP@SsW0rD!
946 kill 12667
947 free
948 history
949 exit

Find the line number of the entry you want to delete—in this case #945—and type:

history -d 945

(Obviously you should replace the 945 with the item number you want to delete!)

Type the history command again and you will see that the entry is gone.

No comments:

Post a Comment