C C++ Java Data Structure Python JavaScript CSS Ajax PL/SQL PHP Puzzles C programs C++ programs Java programs

Home » Linux

sudo, su and chmod commands

sudo command

sudo command stands for “superuser do” & also know as “sudoers”. Sudoers file maintains by the system administrator, who allows to access rights for some commands to particular users. sudo command prompts for root password before executing commands. Without knowing root password, anyone can not access those commands which are available in sudoers file.


sudo command-name

if you are trying to update your system, using apt-get update command. You can not execute this command with out using sudo before it.

ih@linux :~ apt-get update
could not open lock file var/lib/apt/lists/lock -open (13: permission denied)

command will not execute, permission denied message displays. To run successfully use sudo before apt-get update command.

ih@linux :~ sudo apt-get update

Sponsored Links

su command

This cmmand standrs for “switch user”. su command helps us to switch current user to another. Just type the user-name after the su command, it will ask for the password (target user's password).

su is also switches to root account.

To switch root account,
myLinux :~ su

After entering the correct password, you can access root account. Now you can also execute each sudoers command without using sudo command.

chmod command

This command stands for “change mode”, it is used to assign permission to the file/directory for different users.

There are following users on which you can assign directories/files access rights.

  • Owner of the file
  • The members of a group of related users
  • And others

There are following permissions, that can apply on a file/directory.

r - Allow to read the file

w - Allow to write into the file

x - Allow to execute the file

Permissions can be assigned using -rwx rwx rwx

first rwx : read,write,execute permissions for the owner of the file

second rwx : read,write,execute permissions for the group owner of the file

third rwx : read,write,execute permissions for all other users

With chmod command, you can use following set of permissions, to apply desired conditions on a file/directory.

rwx rwx rwx = 111 111 111		[ chmod 777 file-path ]
rw- rw- rw- = 110 110 110		[ chmod 666 file-path ]
rwx --- --- = 111 000 000		[ chmod 700 file-path ]

and so on...

rwx = 111 in binary = 7
rw- = 110 in binary = 6
r-x = 101 in binary = 5
r-- = 100 in binary = 4
chmod 777 /home/file1.txt