The Unix chmod Command

chmod changes the mode of files. The mode of a file controls the access permissions associated with that file. Unix uses three levels of security: ownership, group, and anyone. The read permission means that the user is able to look at the contents of that file. The write permission allows the user to modify the file. The execute permission means that the user is able to execute the file.

Directories have a slightly different behavior. The read permission allows the user to to view the contents of the directory with the ls command. The write permission enables the user to create, delete, and modify files from the directory. The execute permission allows the user to change to the directory with the cd command.

Command syntax:

chmod [options] mode filename(s)

Item Description
-vVerbosely describes changed permissions.
-RRecursively changes permissions of directories and their contents.
--helpPrints a usage message on the screen and exits
modeThe numeric mode of the permissions this file has for all levels. Each digit represents the respective bit pattern permission in the order of Owner, Group, and Anyone. The available permissions are none, execute, write, and read; the values for these permissions are 0, 1, 2, and 4, respectively.
Examples:

chmod 644 myfile.html

This sets permission on a file named myfile.html. It gives the owner read-write access (4+2), the group read access (4), and anyone else also has read access (4).

chmod 777 myfile.html

This gives owner, group, and anyone else read-write-execute access (4+2+1). This is dangerous for your data!

chmod 664 myfile.html

This is a common permission setting for a file. It gives owner and group read-write access, while restricting anyone else to read-only access.

chmod 775 myfiles.dir

This is a common permission setting for a directory. It gives owner and group read-write-execute access (4+2+1), while limiting anyone else to only read-execute access (4+1).
Remember! You must have execute permission to change to a directory.

Back to Unix Commands