Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

ls(1)

chmod(2)

environ(5)

chmod(1)

NAME

chmod − change the permissions mode of a file

SYNOPSIS

chmod [ −fR ] mode filename...
chmod [ugoa ]{ + | - | = }[ rwxlsStTugo] filename...

AVAILABILITY

SUNWcsu

DESCRIPTION

chmod changes or assigns the mode of a file.  The mode of a file specifies its permissions and other attributes.  The mode may be absolute or symbolic. 

An absolute mode is specified using octal numbers:

chmod nnnn filename ...

where n is a number from 0 to 7.  An absolute mode is constructed from the OR of any of the following modes:

4000 Set user ID on execution. 

20#0 Set group ID on execution if # is 7, 5, 3, or 1. 

Enable mandatory locking if # is 6, 4, 2, or 0. 

This bit is ignored if the file is a directory; it may be set or cleared only using the symbolic mode. 

1000 Turn on sticky bit (see chmod(2)). 

0400 Allow read by owner. 

0200 Allow write by owner. 

0100 Allow execute (search in directory) by owner. 

0070 Allow read, write, and execute (search) by group. 

0007 Allow read, write, and execute (search) by others. 

A symbolic mode is specified in the following format:

chmod [ who ] operator [ permission(s) ] filename...

who is zero or more of the characters u, g, o, and a specifying whose permissions are to be changed or assigned:

u user’s permissions

g group’s permissions

o others’ permissions

a all permissions (user, group, and other)

If who is omitted, it defaults to a, but the setting of the file creation mask (see umask in sh(1) or csh(1) for more information) is taken into account.  When who is omitted, chmod will not override the restrictions of your user mask. 

operator is one of +, −, or =, signifying how permissions are to be changed:

+ Add permissions. 

− Take away permissions. 

= Assign permissions absolutely. 

Unlike other symbolic operations, = has an absolute effect in that it resets all other bits.  Omitting permission(s) is useful only with = to take away all permissions. 

permission(s) is any compatible combination of the following letters:

r read permission

w write permission

x execute permission

l mandatory locking

s user or group set-ID

S undefined bit-state (the set-user-ID bit is on and the user execution bit is off)

t sticky bit

T the 1000 bit is turned on, and execution is off (undefined bit-state)

u,g,o indicate that permission is to be taken from the current user, group or other mode respectively. 

Permissions to a file may vary depending on your user identification number (UID) or group identification number (GID).  Permissions are described in three sequences each having three characters:

UserGroupOther
rwxrwxrwx

This example (user, group, and others all have permission to read, write, and execute a given file) demonstrates two categories for granting permissions: the access class and the permissions themselves. 

Multiple symbolic modes separated by commas may be given, though no spaces may intervene between these modes.  Operations are performed in the order given.  Multiple symbolic letters following a single operator cause the corresponding operations to be performed simultaneously. 

The letter s is only meaningful with u or g, and t only works with u. 

Mandatory file and record locking (l) refers to a file’s ability to have its reading or writing permissions locked while a program is accessing that file. It is not possible to permit group execution and enable a file to be locked on execution at the same time. In addition, it is not possible to turn on the set-group-ID bit and enable a file to be locked on execution at the same time.  The following examples, therefore, are invalid and elicit error messages:

chmod g+x,+l filename
chmod g+s,+l filename

Only the owner of a file or directory (or the super-user) may change that file’s or directory’s mode.  Only the super-user may set the sticky bit on a non-directory file.  If you are not super-user, chmod will mask the sticky-bit but will not return an error.  In order to turn on a file’s set-group-ID bit, your own group ID must correspond to the file’s and group execution must be set. 

OPTIONS

−f Force.  chmod will not complain if it fails to change the mode of a file. 

−R Recursively descend through directory arguments, setting the mode for each file as described above.  When symbolic links are encountered, the mode of the target file is changed, but no recursion takes place. 

EXAMPLES

Deny execute permission to everyone:

example% chmod a−x filename

Allow read permission to everyone:

example% chmod 444 filename

Make a file readable and writable by the group and others:

example% chmod go+rw filename
example% chmod 066 filename

Cause a file to be locked during access:

example% chmod +l filename

Allow everyone to read, write, and execute the file and turn on the set group-ID. 

example% chmod =rwx,g+s filename
example% chmod 2777 filename

Absolute changes don’t work for the set-group-ID bit of a directory.  You must use g+s or g-s. 

ENVIRONMENT

If any of the LC_∗ variables ( LC_CTYPE, LC_MESSAGES, LC_TIME, LC_COLLATE, LC_NUMERIC, and LC_MONETARY ) (see environ(5)) are not set in the environment, the operational behavior of chmod for each corresponding locale category is determined by the value of the LANG environment variable.  If LC_ALL is set, its contents are used to override both the LANG and the other LC_∗ variables.  If none of the above variables is set in the environment, the "C"  (U.S. style) locale determines how chmod behaves. 

LC_CTYPE
Determines how chmod handles characters. When LC_CTYPE is set to a valid value, chmod can display and handle text and filenames containing valid characters for that locale.  chmod can display and handle Extended Unix Code (EUC) characters where any individual character can be 1, 2, or 3 bytes wide.  chmod can also handle EUC characters of 1, 2, or more column widths. In the "C" locale, only characters from ISO 8859-1 are valid. 

LC_MESSAGES
Determines how diagnostic and informative messages are presented. This includes the language and style of the messages, and the correct form of affirmative and negative responses.  In the "C" locale, the messages are presented in the default form found in the program itself (in most cases, U.S. English).

SEE ALSO

ls(1), chmod(2), environ(5)

NOTES

chmod permits you to produce useless modes so long as they are not illegal (for instance, making a text file executable).  chmod does not check the file type to see if mandatory locking is meaningful. 

SunOS 5.1/SPARC  —  Last change: 26 Sep 1992

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026