Forrest logo
back to the !! tool

histexpand:tldr:24287

histexpand: Run the previous command as root (`!!` is replaced by the previous command).
$ sudo !!
try on your machine

The command sudo !! is a shorthand way to repeat the previous command with superuser (root) privileges.

To break it down:

  • sudo is a command used in Unix-like systems to run a command with administrative (root) permissions.
  • !! is a special syntax in Unix-like shells that represents the previous command entered.

So when you run sudo !!, it tells the shell to take the previous command and run it with root privileges (if you have the necessary permissions).

For example, if you had previously run the command apt-get update and realized you needed root privileges to execute it, instead of typing the entire command again with sudo, you can simply enter sudo !! and it will run apt-get update with root privileges.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the !! tool