Definition:
The word sudo means superuser do.
When you switch (change your role) to a superuser, you gain every right that belongs to the superuser.
That means only they can run the sudo command with root.
In short, they have all the powers that a normal user cannot use.
Syntax:
sudo [options] command
Options:
-
-u → Run the command as a specified user instead of root.
Example:sudo -u rahul ls /home/rahulHere, the command runs as rahul instead of root.
-
-i → Gives you a shell with complete root authority, just like the root user.
Example:sudo -i -
-k → Clears the sudo time, so next time it will ask for your password again.
Example:sudo -k -
-l → Displays the exact list of commands that you are allowed to run using
sudo.
Example:sudo -l -
!! → Executes the most recent command again, but with root privileges.
Example:sudo !!
Examples:
Install software:
sudo apt-get install git
Change file owner:
sudo chown shobha:developers file.txt
Here, shobha becomes the owner, and developers becomes the group.
Note:
- Whenever you run this command in the terminal, be very careful. Even a single wrong command can damage the whole system.
