Skip to content

chmod reference

Chmod is used to set files permissions (on Linux). It takes a 3-digit code as an argument. Syntax:

chmod [-R] xyz file_or_foldername

* -R is optional and means recursive (changes files in subdirectories too)
* xyz is the 3-digit code (see below)
* file_or_foldername is the file or folder name, but note that you can match several names if using a syntax using partial names, like *stuff* or fi*nam.*

For xyz:
* x is privileges for the owner
* y is privileges for the group (NB: it’s NOT the owner’s group, it’s the group the file belongs to!)
* z is privileges for all other users

x, y and z all work the same way, otherwise: they are a bitflag where:
* 1 = execute (x)
* 2 = write (w)
* 4 = read (r)
This means that to say “read and write” you should use number 6 (=4 + 2). Of course, for giving no permission (no read, write or execute), use 0.

For instance:

chmod 754

Will give the following privileges:
* for owner: read, write and execute (4 + 2 + 1)
* for group: read and execute (4 + 1)
* for all others: read (4)

To read the privileges of the files in a folder, use:

ls -l [optionally filename]

This will output stuff using the letter format, like -rwxr-xr– (equivalent to 754: first dash is a d for a directory but a dash otherwise, the 3 following characters are for owner, the 3 after for group, the 3 last for others)

Posted in Linux.

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Some HTML is OK

or, reply to this post via trackback.

Sorry about the CAPTCHA that requires JS. If you really don't want to enable JS and still want to comment, you can send me your comment via e-mail and I'll post it for you.

Please solve the CAPTCHA below in order to fight spamWordPress CAPTCHA