Run the Last Command as sudo in Ubuntu
Have you found yourself running a command only to realise you need superuser privileges? Instead of retyping everything, there’s a quick method to run the last command as sudo
in Ubuntu.
To do this, simply type sudo !!
and hit Enter. What’s happening here is that the !!
refers to the last command you ran. By adding sudo
before it, you’re effectively re-running that command with elevated privileges.
It’s a small but really good time-saver, especially when you’ve missed the sudo
the first time around. Whether it’s installing software or modifying system files, this simple shortcut gets the job done without having to manually retype the command. Just remember: use it wisely, as running commands with sudo
can make some permanent changes to your system - depending on the command you run!