Chmod is another innocuous but extremely useful Linux command. What does chmod do? Simply put, chmod allows you to change file permissions. For MS-DOS users, it is many ways similar to the "attrib" command, except in many ways it is more flexible and powerful.

Chmod recognizes four classes of users; user [u], group [g], other [o] and all [a]. These distinctions allow you to tailor permissions without having a blanket effect across the entire system, unless you specify it. With chmod you can either allow [+] or deny [-] the ability to run [r], write [w], or execute [x] a file.

Using chmod

The standard syntax is as follows:

chmod [u|g|o|a][+|-][r|w|x] filename

The [u|g|o|a] represent the user specification.
The [+|-] represents whether you wish to allow or deny access.
The [r|w|x] represent the functions you wish to allow or deny.

When you type the command, there is a space between chmod and the commands and a space between the commands and the filename. However, there is no space between the commands.

For example, "chmod go-rw filename" is an example if you what to remove the read and write permissions from the group and other categories.

Absolute setting

Another way to use chmod is through the absolute setting. The absolute setting replaces the commands [u|g|o|a][+|-][r|w|x] with octal numbers. Octal numbers are a numeric system based on eight (hence the octal). Instead of the [u|g|o|a][+|-][r|w|x] commands, you would use the numbers 0-7 to set permissions.

What about the users, you ask? Instead of using a number of user types, the absolute setting system uses the octal number placement. For example the command:

chmod 012 filename

means:
the user has no permissions (0)
the group has execute permission (1)
other has write-only permission (2)

The order is always the same. The first number will always be the user, the second will be the group, and the final number is other. You must list all three numbers when you use absolute setting syntax.