Run the last executed command as root with sudo !!

Jul 20, 2010 - 1 Comment

No I’m not just super excited about the sudo command, the exclamation points are actually part of the usage of the sudo tool. If you want to quickly run the last command executed but as the root superuser, type the following:sudo !! An example of this would be if you’re trying to edit a system file that you need system privileges for. Instead of re-entering the entire command string preceded with sudo, just type sudo !! and the previous command (!!) will be run under sudo.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: Bill Ellis in Command Line, Tips & Tricks

One Comment

» Comments RSS Feed

  1. pederast says:

    !! is not related to sudo. It’s a bash event designator that refers to the last command. !-{n} would refer to the command issued n commands ago. !! is equal to !-1.

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates