Sun Dec 18 02:48:19 GMT 2011

Run last command in bash

Just a quick blog; I couldn't remember how to quickly rerun my last command in bash; yes, I could have pressed up and then enter, but still...

Bash also has a built in mechanism for this:
This is the same as pressing up and enter; although, it can be more powerful, as you can add something like sudo to the beginning:
sudo !!
so for example:
$ /etc/init.d/really_long_filename stop
 * really_long_filename: superuser access required
$ sudo !!
saves a bit of typing there...

You can also look further back in your history and use
!-1 (same as !!)
!-2 command before last
!-3... etc.

Posted by Phill | Permalink