Thursday, May 22, 2008

Remembering Previous Shell Commands

Here is an easy way to re-run your last shell command which contained a certain word. Mind you, this command can be dangerous if you search on the wrong word.

Update: As a commentor has pointed out, in Bash, you cn simply use Ctrl-R. Genious!

#
# Run last bash shell command containing a certain word.
#

`grep SOMEWORD ~/.bash_history | tail -n1 -`

1 comments:

Anonymous said...

If you are using bash then it is less typing (and less dangerous) to type ^r This is because the text entry uses the same shortcut keys as emacs so control-R gives you incremental search back through your history. As you type it will find commands, to go to the next hit press ^r again.