Chmod

related topics
{system, computer, user}
{math, number, function}
{law, state, case}
{group, member, jewish}

The chmod command (abbreviated from change mode) is a Unix command that lets a programmer tell the system how much (or little) access it should permit to a file.[1] It changes the file system modes of files and directories. The modes include permissions and special modes. It is also a C language function in Unix and Unix-like environments.

Contents

History

A chmod command first appeared in AT&T Unix version 1, and is still used today on Unix-like machines.

Usage

The chmod command options are specified like this:

 $ chmod [''options''] ''mode''[,''mode''] ''file1'' [''file2'' ...]

This is used to control the file mode.

To view the current file mode:

 $ ls -l ''file''

or use the stat command to view the octal numerical values ("*" lists all files in current directory)

 $ stat -c '%A %a %n' *

[edit] Octal numbers

See also: Octal notation of file system permissions

The chmod command accepts up to four digits to represent an octal number. The octets refer to bits applied to the file owner, group and other users, respectively. Use of three digits is discouraged because it leaves the fourth as the default and this value is not fixed. The least significant digit sets/resets an additional mode for each of these three sets of bits. Experienced Unix and Linux users tend to recommend that the user of this command check the man page (man chmod) on the system of interest.

Particular care should be taken when a directory is the target because the effect is not intuitive. In addition, it will not work on all file types. For example, it has no effect on a symbolic link. myfile :

 $ chmod 664 myfile
 $ ls -l myfile
 -rw-rw-r--  1   57 Jul  3 10:13  myfile

Since the setuid, setgid and sticky bits are not set, this is equivalent to:

 $ chmod 0640 myfile

[edit] Symbolic modes

See also: Symbolic notation of file system permissions

chmod also accepts finer-grained symbolic notation, all permissions and special modes are represented by its mode parameter. One way to adjust the mode of files or directories is to specify a symbolic mode. The symbolic mode is composed of three components, which are combined to form a single string of text:

 $ chmod [''references''][''operator''][''modes''] ''file1'' ...

The references (or classes) are used to distinguish the users to whom the permissions apply. If no references are specified it defaults to “all” but modifies only the permissions allowed by the umask. The references are represented by one or more of the following letters:

Reference Class Description
u user the owner of the file
g group users who are members of the file's group
o others users who are not the owner of the file or members of the group
a all all three of the above, is the same as ugo

The chmod program uses an operator to specify how the modes of a file should be adjusted. The following operators are accepted:

Operator Description
+ adds the specified modes to the specified classes
- removes the specified modes from the specified classes
= the modes specified are to be made the exact modes for the specified classes

The modes indicate which permissions are to be granted or taken away from the specified classes. There are three basic modes which correspond to the basic permissions:

Mode Name Description
r read read a file or list a directory's contents
w write write to a file or directory
x execute execute a file or recurse a directory tree
X special execute which is not a permission in itself but rather can be used instead of x. It applies execute permissions to directories regardless of their current permissions and applies execute permissions to a file which already has at least 1 execute permission bit already set (either user, group or other). It is only really useful when used with '+' and usually in combination with the -R option for giving group or other access to a big directory tree without setting execute permission on normal files (such as text files), which would normally happen if you just used "chmod -R a+rx .", whereas with 'X' you can do "chmod -R a+rX ." instead
s setuid/gid details in Special modes section
t sticky details in Special modes section

The combination of these three components produces a string that is understood by the chmod command. Multiple changes can be specified by separating multiple symbolic modes with commas.

Full article ▸

related documents
AltiVec
Fourth-generation programming language
ReiserFS
Java Servlet
Ext2
CPAN
Amdahl's law
Priority queue
Z-buffering
Machine code
Enterprise Objects Framework
Talker
Wikipedia:Free On-line Dictionary of Computing/E - H
DEFLATE
Parrot virtual machine
Object Linking and Embedding
Zope
GNU Privacy Guard
Queueing theory
Byte
Wikipedia:Free On-line Dictionary of Computing/L - N
Rsync
MMX (instruction set)
Maple (software)
Locality of reference
ACID
Microsoft Access
XUL
Ada (programming language)
Simula