What is the sudo command ?
The word sudo means superuser do. When you use the sudo command, you can run commands with superuser (root) privileges. Users who have sudo permission can perform administrative tasks that a normal user cannot perform. In short, it allows authorized users to use the powers of the superuser.
Syntax:
sudo [options] command
Options:
- -u
sudo -u rahul ls /home/rahul
Here, the command runs asrahulinstead 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.
Example 1: Install software
Command:
sudo apt-get install git
Example 2: Change file owner
Command:
sudo chown shobha:developers file.txt
Explanation:
Here, shobha becomes the owner, and the developers becomes the group.












