Browse By

The Basics of CHMOD

What is CHMOD?

CHMOD is a Unix shell command, short for change mode, that can change the permissions of a file or directory. CHMOD uses references (or classes), operators, and modes to assign permissions for users to files. CHMOD can be used in a string notation and octal notation, which is represented in numbers instead of a string.

How can I see the permissions?

The Unix File System Permissions are easily viewable by a directory listing, using a command like ls. This listing will show the current file permissions in the string or symbolic notation of 10 characters. The first character displays the file type and the next three sets of three characters represent the file permissions per class (owner, group, others respectively). You can see an example ls listing below:

$ ls -l test
drw-rw----   2 testuser  testuser       96 Dec  8 12:53 testdir
-rw-rw----   2 testuser  testuser       96 Dec  8 12:53 testfile

How can I change the permissions?

You can use CHMOD two different ways (different syntaxes as noted above) to change the permissions. A string notation and octal notation are available, one being a symbolic syntax and the other being a numerical syntax. String notation uses “r”, “w”, and “x” to change the permissions while octal notation uses 4 for “r”, 2 for “w”, and 1 for “x”. These numbers are added together to get the appropriate permissions (For example: 6 = 4+2 = rw). You can check out a simple CHMOD JavaScript calculator that calculates the octal notation for the permissions you choose. You can also see some example uses of both notations below:

String Notation

chmod u=+rw,go=r testfile - Add read/write to the user, read to group/others
chmod o= testfile         - Remove all permissions for others
chmod -w testfile         - Remove write permissions for all

Octal Notation

chmod 0644 testfile       - Read/write for the user, read for group/others
chmod 0660 testfile       - No permissions for others
chmod 0444 testfile       - No write permissions for all

%d bloggers like this: