Run same command again but as root

Sometimes when I run a command I don't notice that I needed to run it as super user to have enough permission.

Is there a way to run the same command again but as a super user?


Solution 1:

The simplest way is to run:

sudo !!

This will run the last command but as super user.

Source.

Solution 2:

​​​​​​​​​​​​​​​​​​​​​​​​​​​​​enter image description here

​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​Answer: you enter sudo !! straight afterwards to repeat the previous command with escalated privileges.

edit: Image found via reddit, and it's a parody of the original xkcd comic by Randall Munroe.

Solution 3:

You could try the up-arrow key to scroll through your old commands and rewrite/change them and add the sudo in front of them. (the home button above the arrow keys will set the position to the beginning.)

I dislike the sudo !! idea, because sometimes you add another command in between and don't remember anymore.