Modes (Unix)

Modes are the file system permissions given to "user", "group" and "others" classes to access files under Unix. They are shown when listing files in long format, or, if access control lists are in use, using getfacl. Modes can be changed with chmod (for traditional Unix permissions) or with setfacl (for access control lists).

Format

For traditional Unix permissions, 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". Except that when no references are explicitly specified, the final outcome is masked by the umask value. The references are represented by one or more of the following letters:

ReferenceClassDescription
uuserthe owner of the file
ggroupusers who are members of the file's group
oothersusers who are not the owner of the file or members of the group
aallall 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:

OperatorDescription
+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:

ModeNameDescription
rreadread a file or list a directory's contents
wwritewrite to a file or directory
xexecuteexecute a file or recurse a directory tree
Xspecial executewhich 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
ssetuid/giddetails in Special modes section
tstickydetails 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.

String mode examples

For example, the following command would be used to add the read and write permissions to the user and group classes of a file or directory named sample:

$ chmod ug+rw sample
$ ls -ld sample
drw-rw----   2 unixguy  unixguy       96 Dec  8 12:53 sample

This command removes all permissions, allowing no one to read, write, or execute the file named sample.

$ chmod a-rwx sample
$ ls -l sample
----------   2 unixguy  unixguy       96 Dec  8 12:53 sample

The following command changes the permissions for the user and the group to read and execute only (no write permission) on sample.

$ # Sample file permissions before command
$ ls -ld sample
drw-rw----   2 unixguy  unixguy       96 Dec  8 12:53 sample
$ chmod ug=rx sample
$ ls -ld sample
dr-xr-x---   2 unixguy  unixguy       96 Dec  8 12:53 sample

See also

This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.