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. By using it, they can install or deny any Linux command. In short, they have all the powers that a normal user cannot use.
Syntax:
Sudo [options] command
Options:
- -u →
sudo -u rahul ls /home/rahul
Here, the command runs as rahul instead of root.
- -i →
sudo -i
It gives you a shell with complete root authority, just like the root user.
- -k →
sudo -k
It clears the sudo time, so next time it will ask for your password again.
- -l →
sudo -l
It displays the exact list of commands that you are allowed to run using sudo.
- !! →
sudo !!
It executes the most recent command again, but with root privileges.
Examples
Install software:
sudo apt-get install git
Change file owner:
sudo chown shobha: developers file.txt
Here, shobha becomes the owner, and the developers become the group.
Note
Whenever you run this command in the terminal, be very careful. Even a single wrong command can damage the whole system.