xref: /original-bsd/bin/chmod/chmod.1 (revision e4dd4c49)
Copyright (c) 1989 The Regents of the University of California.
All rights reserved.

Redistribution and use in source and binary forms are permitted
provided that the above copyright notice and this paragraph are
duplicated in all such forms and that any documentation,
advertising materials, and other materials related to such
distribution and use acknowledge that the software was developed
by the University of California, Berkeley. The name of the
University may not be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.

@(#)chmod.1 6.5 (Berkeley) 04/28/90

CHMOD 1 ""
C 7
NAME
chmod - change file modes
SYNOPSIS
chmod [-fR] mode file ...
DESCRIPTION
The chmod utility modifies the file mode bits of the listed files as specified by the mode operand.

The options are as follows:

-f If the -f option is given, chmod will still exit 0 and not complain if it fails to change the mode on a file.

-R Traverse a file hierarchy. For each file that is of type directory, chmod changes the mode of all files in the file hierarchy below it followed by the mode of the directory itself.

Symbolic links are not indirected through, nor are their modes altered.

Only the owner of a file or the super-user is permitted to change the mode of a file.

The chmod utility exits 0 on success, and >0 if an error occurs.

MODES
Modes may be absolute or symbolic. An absolute mode is an octal number constructed by or 'ing the following values:

10 4000 set-user-ID-on-execution

.ns

2000 set-group-ID-on-execution

.ns

1000 sticky bit, see chmod(2)

.ns

0400 read by owner

.ns

0200 write by owner

.ns

0100 execute (or search for directories) by owner

.ns

0070 read, write, execute/search by group

.ns

0007 read, write, execute/search by others

The read, write, and execute/search values for group and others are encoded as described for owner.

The symbolic mode is described by the following grammar:

10 mode ::= clause [ , clause ] ...

.ns

clause ::= [ who ... ] [ action ... ] last_action

.ns

action ::= op perm ...

.ns

last_action ::= op [ perm ... ]

.ns

who ::= a | u | g | o

.ns

op ::= + | - | =

.ns

perm ::= r | s | t | w | X | x

The who symbols ``u'', ``g'', and ``o'' specify the user, group, and other parts of the mode bits, respectively. The who symbol ``a'' is equivalent to ``ugo''.

The perm symbols represent the portions of the mode bits as follows:

10 r The read bits.

.ns

s The set-user-ID-on-execution and set-group-ID-on-execution bits.

.ns

t The sticky bit.

.ns

w The write bits.

.ns

x The execute/search bits.

.ns

X The execute/search bits if the file is a directory or any of the execute/search bits are set in the original (unmodified) mode. Operations with the perm symbol ``X'' are only meaningful in conjunction with the op symbol ``+'', and it is ignored in all other cases.

The op symbols represent the operation performed, as follows:

+ If no value is supplied for perm , the ``+'' operation has no effect. If no value is supplied for who , each permission bit specified in perm , for which the corresponding bit in the file mode creation mask is clear, is set. Otherwise, the mode bits represented by the specified who and perm values are set.

- If no value is supplied for perm , the ``-'' operation has no effect. If no value is supplied for who , the mode bits represented by perm are cleared for the owner, group and other permissions. Otherwise, the mode bits represented by the specified who and perm values are cleared.

= The mode bits specified by the who value are cleared, or, if no who value is specified, the owner, group and other mode bits are cleared. Then, if no value is supplied for who , each permission bit specified in perm , for which the corresponding bit in the file mode creation mask is clear, is set. Otherwise, the mode bits represented by the specified who and perm values are set.

Each clause specifies one or more operations to be performed on the mode bits, and each operation is applied to the mode bits in the order specified.

Operations upon the other permissions only (specified by the symbol ``o'' by itself), in combination with the perm symbols ``s'' or ``t'', are ignored.

EXAMPLES

``644'' make a file readable by anyone and writable by the owner only.

``go-w'' deny write permission to group and others.

``=rw,+X'' set the read and write permissions to the usual defaults, but retain any execute permissions that are currently set.

``+X'' make a directory or file searchable/executable by everyone if it is already searchable/executable by anyone.

``755'' or ``u=rwx,go=rx'' make a file readable/executable by everyone and writeable by the owner only.

``go='' clear all mode bits for group and others.

BUGS
There's no perm option for the naughty bits.
ENVIRONMENT
"SEE ALSO"
install(1), chmod(2), fts(2), stat(2), umask(2), setmode(3), chown(8)
STANDARDS
The chmod function is expected to be POSIX 1003.2 compatible with the exception of the perm symbols ``t'' and ``X'' which are not included in that standard.