I came across a new blog (seems to have come on-line in March) http://www.epoxyjournal.com. One of the entries was about how to clear command history. Everyone has inadvertently pasted or typed something into the wrong shell. Sometimes its worthwhile to clean up after yourself and sometimes its not. I figured I would offer a suggestion for the times you want to avoid having your embarrassing moments in your ~/.bash_history.

Instead of blowing away your entire current buffer with history -c you can redirect it to another file, flush the buffer to the file, clean it up then append it to your ~/.bash_history. Sure its more work then abandoning your history but insert Godwin’s Law.

So it might look something like this.

$ echo some long one liner you want to preserver
$ echo something embarrassing
$ export HISTFILE=~/tmphistfile
$ history -a
$ grep -v embarrassing ~/tmphistfile >> ~/.bash_history
# re-point your history file to the right one, or just exit the shell

Matt Simmons thought a little oops utility would be nice. So here is my shoot from the hip attempt, haven’t extensively tested it but I think it works.

# wipe your history of lines that match the input
# Usage: oops <embarrassing string>

history -a
grep -v $1 $TEMPHIST >> ~/.bash_history
history -c
history -r