Linux: Managing the permission of file

Chmod command

  • chmod command is used to change the permissions of a file or directory.
  • Consider a file msc which has the permission as rwxr-x--x

Thus it signifies that

  1. The owner can read, write and execute the file msc
  2. The members of the group can read and execute the file but can not write
  3. All others can only execute the file msc
      r = read , w =write, x = execute
  • These permissions can be encoded numerically. The weights assigned to the three permissions are :
    r = 4
    w = 2
    x = 1
    When all the permissions are available, the total weightage or value is
    4 + 2 + 1 = 7.
  • So owner of msc (rwx) has permission weightage = 7
  • Group permission for msc (r-x) has weightage = 5
  • The permission for the rest is 1 (--x)
  • Thus msc has the permission as 751
  • If everybody be given all the permission then it amounts to 777
  • The existing file permission can be changed by the owner of the file or the super user (root).
  • The way to change these permissions is by using the chmod command. It changes the mode of the file when it is executed.
  • If we want the permission be set as owner all the permissions, group and others none then it will be chmod 700 msc
  • If you see the listing of msc now the permission will be displayed as rwx------
  • This way of changing the file permission is referred to as the absolute mode.

  • There is syntax for chmod that changes permissions, which constitutes the symbolic mode:

  • Its general form is chmod (who) (+/-/=) (permission) file
  • who refers to whom the permissions are to be assigned. It may be user or owner (u), group (g) or others (o). If none is specified, all are assumed.
  • The + refers to add permission and – refers to remove permission and = instructs to add the specified permission and take away all others if present.
  • The specified permissions are r, w, or x.

Example: chmod go-x msc (This takes away the execute permission from group as well as others)

Example: chmod go+r, go-w msc (This gives read permission and takes away write permission from group and others)

Example: chmod go=r,u=rw msc ( This gives read and write permission to the owner and read permission to group and others. The same permission giving can be achieved by chmod 644 msc)

Linux: Summary of some user and group related commands << Previous
Next>> Linux: Managing the permissions of directory

Our aim is to provide information to the knowledge seekers. 

comments powered by Disqus