Have you ever encountered an error message that says “permission denied” while trying to use a command line tool? Or maybe the command you’re trying to use requires root access? Instead of retyping the entire command followed by sudo, you can use a simple trick to re-execute the last command with sudo privileges using “sudo !!”. This works on both MacOS / Mac OS X and Linux.
Executing the Last Command with Root Access
To quickly execute the last command as root, simply type:
sudo !!
This will prepend “sudo” to the last executed command, allowing you to run it with root privileges. You will be prompted to enter your administrator password to complete the session.
This trick works with virtually every command line tool and command, saving you time and effort.
Benefits of Using sudo !!
- The sudo !! trick saves time and effort, especially when working on system files that require root permissions.
- This guide is free and easy to follow.
FAQs
What is sudo !!?
sudo !! is a command used to re-execute the last command with root privileges by appending “sudo” to it.
Does sudo !! work on MacOS and Linux?
Yes, the sudo !! trick works on both MacOS / Mac OS X and Linux command lines.
Do I need to enter my administrator password to use sudo !!?
Yes, you will be prompted to enter your administrator password to complete the session.
Can I use sudo !! with any command line tool or command?
Yes, the sudo !! trick works with virtually every command line tool and command.
Final Thoughts
Using sudo !! is a simple and effective way to quickly run the last executed command with root access, saving you time and effort. If you have any questions or suggestions, please feel free to leave a comment or contact us.