Linux tip: repeat a command as sudo

When you run a command in the terminal, and realize it requires superuser permissions, use the following command to re-run the command as superuser:

sudo !!

Here is an example scenario:

apt-get install myapplication
(permission denied)
sudo !!

The best part is that you can use this to prefix your command with anything. In the example below, I forgot to put cd in front of my file path.

nicolas@nicolas-Revo ~ $ Backup
No command 'Backup' found, did you mean:
 Command 'rackup' from package 'ruby-rack' (universe)
 Command 'backup' from package 'openafs-client' (universe)
 Command 'packup' from package 'packup' (universe)
Backup: command not found

nicolas@nicolas-Revo ~ $ cd !!

nicolas@nicolas-Revo ~/Backup $ 

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see