Linux Files and File Permission


    Prepared By Santosh Sharma
Each file belongs to a specific user and group. Access
to the files is controlled by user, group, and what is
called other. The term, other, is used to refer to
someone who is not the user (owner) of the file, nor is
the person a member of the group the file belongs to.

File names can be up to 256 characters long with "-", "_",
and "." characters along with letters and numbers.
When a long file listing is done, there are 10 characters
that are shown on the left that indicate type and
permissions of the file. File permissions are shown
according to the following syntax example:
drwerwerwe
The first character indicates the type of file, and the next three indicate
read, write, and execute permission for each of the three user types,
user, group and other. Since there are three types of permission for three
users, there are a total of nine permission bits.



  1      2     3       4       5      6       7       8      9      10

 File   User Permissions      Group Permissions       Other Permissions

Type Read Write Execute Read Write Execute Read Write Execute

  d      r     w       e        r     w       e        r     w       e
Now that you can read file permissions, you should learn about how you
can set or modify permissions. You would use the chmod program for
this. To change file permissions, you need to be either the user or root.
The syntax of the chmod command is quite simple. File permissions may
be defined for users (u), groups (g) and others (o).

An example of the chmod command will be



chmod u-x,g+w,o+rw somefile

The chmod command here takes away execute permission from the
user, sets the write access bit for the group and also gives read and
write access to everyone else.
There is another way in which you can specify the file
permissions. The permission bits r,w and x are assigned
a number.

r=4
w=2
x=1

Now you can use numbers, which are the sum of the various
 permission bits. E.g - rwx will be 4+3+1 = 7. rx becomes
4+1 = 5. The chmod command now becomes chmod xyz
filename where x,y and z are numbers representing the
permissions of user, group and others respectively. Each
number is the sum of the permissions to be set and are
calculated as given above.
Chmod 644 somefile

  6 = 4 + 2 = rw
  4=r
  4=r

In addition to the file permission, you can also modify the owner and
group of the file. The chown program is used here and its syntax is very
simple. You need to be the owner of a file or root to do this.

chown new-owner somefile

chown newbie somefile

To change group, user the chgrp command. Syntax is similar to chown. You
will need to be the owner of the file and also belong to the same group as
the file, or you should be root.

chgrp new-grp somefile

Linux files and file permission

  • 1.
    Linux Files andFile Permission Prepared By Santosh Sharma
  • 2.
    Each file belongsto a specific user and group. Access to the files is controlled by user, group, and what is called other. The term, other, is used to refer to someone who is not the user (owner) of the file, nor is the person a member of the group the file belongs to. File names can be up to 256 characters long with "-", "_", and "." characters along with letters and numbers. When a long file listing is done, there are 10 characters that are shown on the left that indicate type and permissions of the file. File permissions are shown according to the following syntax example: drwerwerwe
  • 3.
    The first characterindicates the type of file, and the next three indicate read, write, and execute permission for each of the three user types, user, group and other. Since there are three types of permission for three users, there are a total of nine permission bits. 1 2 3 4 5 6 7 8 9 10 File User Permissions Group Permissions Other Permissions Type Read Write Execute Read Write Execute Read Write Execute d r w e r w e r w e
  • 4.
    Now that youcan read file permissions, you should learn about how you can set or modify permissions. You would use the chmod program for this. To change file permissions, you need to be either the user or root. The syntax of the chmod command is quite simple. File permissions may be defined for users (u), groups (g) and others (o). An example of the chmod command will be chmod u-x,g+w,o+rw somefile The chmod command here takes away execute permission from the user, sets the write access bit for the group and also gives read and write access to everyone else.
  • 5.
    There is anotherway in which you can specify the file permissions. The permission bits r,w and x are assigned a number. r=4 w=2 x=1 Now you can use numbers, which are the sum of the various permission bits. E.g - rwx will be 4+3+1 = 7. rx becomes 4+1 = 5. The chmod command now becomes chmod xyz filename where x,y and z are numbers representing the permissions of user, group and others respectively. Each number is the sum of the permissions to be set and are calculated as given above.
  • 6.
    Chmod 644 somefile 6 = 4 + 2 = rw 4=r 4=r In addition to the file permission, you can also modify the owner and group of the file. The chown program is used here and its syntax is very simple. You need to be the owner of a file or root to do this. chown new-owner somefile chown newbie somefile To change group, user the chgrp command. Syntax is similar to chown. You will need to be the owner of the file and also belong to the same group as the file, or you should be root. chgrp new-grp somefile