Linux/Unix - Changing Permissions with Chmod

Linux/Unix - Changing Permissions with Chmod

  • Linux
  • 2 mins read

The symbolic form is one of two ways the Linux/Unix system tracks permissions. The other method, the numeric form, comes in very handy when changing permissions with the chmod command.

As you'd expect, the numeric form uses numerals to track permissions. This is done in a very quirky way, however, and is probably more complicated than it need be, forcing you to add up three different sets of numbers in determining who has what permissions. Note that the actual types of permissions have not changed; only the way of listing them has changed.

The numeric form uses modes to list permissions. A mode is an octal number in one of the forms listed below:

Numeral

Meaning

400

The owner has read permission

200

The owner has write permission

100

The owner has execute permission

040

Group has read permission

020

Group has write permission

010

Group has execute permission

004

All users have read permission

002

All users have write permission

001

All users have execute permission

Now all you need to do is add the numerical values associated with each level of permission. Below are some examples, please have a look.

Linux/Unix Chmod Command Examples

To change the permissions for the my_file file, giving the entire world permission to read, write, and execute the file (400 + 200 + 100 + 040 + 020 + 010 + 004 + 002 + 001 = 777), you 'd use a command line like:

$ chmod 777 my_file

To change the permission to where only the owner can read, write, and execute the file my_file (400 + 200 + 100  = 700), you'd use the following command:

$ chmod 700 my_file

To change the permission to where only the owner can read, write, and execute the file, with members of the group also having the ability to read, write, and execute the file (400 + 200 + 100 + 040 + 020 + 010 = 770), you'd use the following command:

$ chmod 770 my_file

To change the permission to where only the owner can read, write, and execute the file, with members of the group and the world having the ability to read the file (400 + 200 + 100 + 040 + 004 = 744), you'd use the following command:

$ chmod 744 my_file

You can also change the permissions of the contents of an entire directory with chmod by using it with the -R option. The following command line makes the entire contents of the my_dir readable for only the owner of the directory:

$ chmod -R 700 my_dir