chmod command is used to change the permission of a file in Linux. In Linux, there is a set of rules for each file that defines who can access that file, and how they can access it. These rules are called file permissions or file modes. The command name chmod stands for “change mode”, and it is used to define the way a file can be accessed.
chmod [options] <permissions> <filename>
Note: If no options are specified, chmod modifies the permissions of the file specified by filename to the permissions specified by permissions.
Permissions defines the permissions for the owner of the file (the “user”), members of the group who owns the file (the “group”), and anyone else (“others”). There are two ways to represent these permissions: with symbols (alphanumeric characters), or with octal numbers (the digits 0 through 7).
Example[with symbols]: chmod u=rwx,g=rx,o=r test_file
This is an example of using symbolic permissions notation which change the permission of a file in Linux. The letters u, g, and o stand for “user”, “group”, and “other”. The equals sign (“=”) means “set the permissions exactly like this,” and the letters “r”, “w”, and “x” stand for “read”, “write”, and “execute”, respectively.
Example[with octal numbers]: chmod 754 test_file
Here the digits 7, 5, and 4 each individually represent the permissions for the user, group, and others, in that order. Each digit is a combination of the numbers 4, 2, 1, and 0:
4 stands for “read”,
2 stands for “write”,
1 stands for “execute”, and
0 stands for “no permission.”
So 7 is the combination of permissions 4+2+1 (read, write, and execute), 5 is 4+0+1 (read, no write, and execute), and 4 is 4+0+0 (read, no write, and no execute).