chmod ( Linux command tutorials )

  • In Linux and Unix, everything is file. Directories are files, files are files at the same time, devices are files.

  • All of the files on system will have permissions.

  • It's like Attribute of DOS or Windows File and Folder.

  • This permission allows to prevent other from viewing, modifying or executing.

  • The super user "root" has the ability to access any file on the system.

  • This command is used to modify the permissions given on a particular file.

 

Permission type

Description

r

Stands for Read permission i.e. view. chmod option is r or 4.

w

Stands for Write permission i.e. edit. chmod option is w or 2

x

Stands for Execute Permission. chmod option is x or 1

 

  • There are three types of user permissions for files.

User type

ls output Description

Owner / User (u)

-rwx------

Group (g)

----rwx---

Other (o)

-------rwx

 

 

  • We have created a file test.txt

  • As seen in the snapshot the permissions of test.txt are given as -rw-rw-r—

  • The first character – is for directory.

 

 

  • In above example for test.txt file permission is –rw—rw-r--.

  • So permission is for Owner (rw-) i.e. Read and Write

  • For Group (rw-) i.e. Read and Write.

  • For Other (r- -) i.e. Read only.

 

chmod 777 test.txt

  • This command will assign the read write and execute permission to the user, group and others.

  • 777 stands for the binary code 111 111 111 giving read, write and execute permission to user, group and other respectively.

 

chmod u+r test.txt

  • This command will assign the read permission to user on test.txt file

 

chmod u+rx test.txt

  • This command will assign the read and execute permission to user on test.txt file.

 

chmod ug+r test.txt

  • This command will assign the read permission to user and group on test.txt file.

 

 

border