SporkBomb

the daily experiences of a technophile

Clearing Out Your Bash History (0)

January 18th, 2008 by Emil in CLI, Linux

Sometimes you’re forced to write passwords directly into your CLI of choice due to poor programming practices, poor user practices (if you’re me), or simply because you don’t have time to be the James Bond of the CLI. In such cases you need to make sure that the password doesn’t stay logged on your system.

Everything you type (that’s not intentionally obfuscated by the application or OS) into your CLI is usually logged. I use bash for my CLI needs. In bash all commands written in the CLI are stored in a file located in

~/.bash_history

or

/home/(username)/.bash_history

If you do a

tail ~/.bash_history

you will see all the commands (up to around 200 by default) that you’ve written into your terminal. This is usually very helpful because it lets you retrace your steps if something breaks, and allows you an easy way to recall long commands to the screen (by pressing the up arrow several times).

Sometimes you need to erase your bash history because it may contain important information. This is very easy to do. The first option is to run

history -c

This will nuke your whole history file. What if you want to only remove a specific entry in your history file? You’re in luck! the history command gives you a chance to do that

history | tail

This pipes the output of your perhaps long history into a readable format with the latest commands first. Now you have to find the number of the command you want to remove. Get it and remember it.

history -d (number)

That’s all! This should give you a reasonable assurance that your commands will not be visible to would be root pirates (a.k.a. hackers… arrrrrrr!), smart dogs, and curious siblings.

Leave a Reply