We can change the permissions of files or directories using the chmod
command. Most probably you have seen the notation -rwxrwxrwx
in files and directories. The first triplet refers to the user, the second one to the group and the third one to all other users.
The r
is for Read the w
is for Write and the x
is for Execute. So for example, if you want to give the following permissions to the my_file.txt
:
- The user (u) has full permissions, i.e. read (r), write (w), execute (e)
- The group (g) can only read (r) and execute (e)
- The others (o) can only read (r)
Then you can type:
chmod u=rwx,g=rx,o=r my_file.txt
Notice that the u,g,o refer to user, group and other respectively and the r, w, x, to read, write and execute. We can run the same command by using the octal notation like:
chmod 754 my_file.txt
Where each digit represent the permission for each member. So the 7 is for user, the 5 is for group and the 4 is for other. These numbers are coming by converting the binary numbers to decimal as explained in the image below:
If you want to get more information on how you can convert a binary number to decimal please visit the cool conversion. So the 111 binary is 7 in decimal.