chmod

File permissions

Each file has in its i-node information concerning the permissions that a user can have on this file.

There are 3 types of permissions:

  • reading (r)

  • writing / editing (w)

  • execution (x)    There are 3 types of access to a file:

  • by the user (u)

  • by the user group (g)

  • by others (o)

The permissions for a file are accessible by the command ls -l (1st column).

A first character indicates the file type:

character meaning
d directory
- single file
l symbolic link

The next nine characters give the permissions in the order user, group, and others.

For example, rwxr-x--- means that the user has read, write, and execute permissions, other users of the group have permissions in read and execute (but not in modification), and the other users (except those of the user group) have no permission.

Modification of the permissions

The command chmod allows to modify the permissions of a file.

For each permission and each access, one can define a bit which is true if access is allowed, false otherwise. For each type of access, the three permission bits (rwx) can be grouped into 1 byte:

binary decimal (byte) permissions meaning
000 0 --- no permission
100 4 r-- simple reading
110 6 rw- reading + writing
101 5 r-x reading + execution
111 7 rwx read + write + execution

The command chmod accepts two types of arguments for the permissions: either an alphabetic form (rwx) or a numeric form (0,4,5, etc).

# Use of chmod
chmod permission file [file...]
ls -l a
# Numeric permission (decimal triplet)
chmod 777 a
ls -l a
chmod 664 a
ls -l a
# Modification by adding or substracting
chmod o+x a
ls -l a
chmod g-wx a
# Absolute permission
chmod u=rwx a
chmod u=rwx,g=rx,o=r a
# a: all
chmod a=rwx a