date and time created 91/03/07 20:27:47 by bostic
[unix-history] / usr / src / bin / chmod / chmod.1
CommitLineData
b5dc1377 1.\" Copyright (c) 1989, 1990 The Regents of the University of California.
6aa2c2f8
KB
2.\" All rights reserved.
3.\"
27c71911 4.\" %sccs.include.redist.man%
6aa2c2f8 5.\"
7bcabb1e 6.\" @(#)chmod.1 6.13 (Berkeley) %G%
aed64a6e 7.\"
b5dc1377
CL
8.Dd
9.Dt CHMOD 1
10.Os BSD 4.4
11.Sh NAME
12.Nm chmod
7bcabb1e 13.Nd change file modes
b5dc1377
CL
14.Sh SYNOPSIS
15.Nm chmod
7bcabb1e 16.Op Fl R
b5dc1377
CL
17.Ar mode
18.Ar file ...
19.Sh DESCRIPTION
6aa2c2f8 20The
b5dc1377 21.Nm chmod
6aa2c2f8
KB
22utility modifies the file mode bits of the listed files
23as specified by the
b5dc1377 24.Ar mode
6aa2c2f8 25operand.
b5dc1377 26.Pp
6aa2c2f8 27The options are as follows:
7bcabb1e
CL
28.Bl -tag -width Ds
29.It Fl R
6aa2c2f8
KB
30Traverse a file hierarchy.
31For each file that is of type directory,
b5dc1377 32.Nm chmod
6aa2c2f8
KB
33changes the mode of all files in the file hierarchy below it followed
34by the mode of the directory itself.
7bcabb1e 35.El
b5dc1377 36.Pp
6aa2c2f8 37Symbolic links are not indirected through, nor are their modes altered.
b5dc1377 38.Pp
6aa2c2f8
KB
39Only the owner of a file or the super-user is permitted to change
40the mode of a file.
b5dc1377 41.Pp
6aa2c2f8 42The
b5dc1377 43.Nm chmod
6aa2c2f8 44utility exits 0 on success, and >0 if an error occurs.
b5dc1377 45.Sh MODES
6aa2c2f8
KB
46Modes may be absolute or symbolic.
47An absolute mode is an octal number constructed by
7bcabb1e 48.Ar or Ap ing
6aa2c2f8 49the following values:
7bcabb1e
CL
50.Pp
51.Bl -tag -width 6n -compact -offset indent
52.It Li 4000
6aa2c2f8 53set-user-ID-on-execution
7bcabb1e 54.It Li 2000
6aa2c2f8 55set-group-ID-on-execution
7bcabb1e 56.It Li 1000
6aa2c2f8 57sticky bit, see chmod(2)
7bcabb1e 58.It Li 0400
aed64a6e 59read by owner
7bcabb1e 60.It Li 0200
aed64a6e 61write by owner
7bcabb1e 62.It Li 0100
6aa2c2f8 63execute (or search for directories) by owner
7bcabb1e 64.It Li 0070
6aa2c2f8 65read, write, execute/search by group
7bcabb1e 66.It Li 0007
6aa2c2f8 67read, write, execute/search by others
7bcabb1e 68.El
b5dc1377 69.Pp
6aa2c2f8
KB
70The read, write, and execute/search values for group and others
71are encoded as described for owner.
b5dc1377 72.Pp
6aa2c2f8 73The symbolic mode is described by the following grammar:
7bcabb1e
CL
74.Bd -literal -offset indent
75mode ::= clause [, clause ...]
76clause ::= [who ...] [action ...] last_action
77action ::= op [perm ...]
78last_action ::= op [perm ...]
79who ::= a | u | g | o
80op ::= + | \- | =
81perm ::= r | s | t | w | X | x | u | g | o
82.Ed
b5dc1377 83.Pp
6aa2c2f8 84The
b5dc1377 85.Ar who
6aa2c2f8
KB
86symbols ``u'', ``g'', and ``o'' specify the user, group, and other parts
87of the mode bits, respectively.
d7ba284c 88The
b5dc1377 89.Ar who
d7ba284c 90symbol ``a'' is equivalent to ``ugo''.
b5dc1377 91.Pp
6aa2c2f8 92The
b5dc1377 93.Ar perm
6aa2c2f8 94symbols represent the portions of the mode bits as follows:
7bcabb1e
CL
95.Pp
96.Bl -tag -width Ds -compact -offset indent
97.It r
6aa2c2f8 98The read bits.
7bcabb1e 99.It s
6aa2c2f8 100The set-user-ID-on-execution and set-group-ID-on-execution bits.
7bcabb1e 101.It t
d7ba284c 102The sticky bit.
7bcabb1e 103.It w
6aa2c2f8 104The write bits.
7bcabb1e 105.It x
6aa2c2f8 106The execute/search bits.
7bcabb1e 107.It X
d7ba284c
KB
108The execute/search bits if the file is a directory or any of the
109execute/search bits are set in the original (unmodified) mode.
110Operations with the
b5dc1377 111.Ar perm
d7ba284c 112symbol ``X'' are only meaningful in conjunction with the
b5dc1377 113.Ar op
d7ba284c 114symbol ``+'', and it is ignored in all other cases.
7bcabb1e 115.El
b5dc1377 116.Pp
6aa2c2f8 117The
b5dc1377 118.Ar op
6aa2c2f8 119symbols represent the operation performed, as follows:
7bcabb1e
CL
120.Bl -tag -width 4n
121.It +
6aa2c2f8 122If no value is supplied for
b5dc1377 123.Ar perm ,
6aa2c2f8
KB
124the ``+'' operation has no effect.
125If no value is supplied for
b5dc1377 126.Ar who ,
6aa2c2f8 127each permission bit specified in
b5dc1377 128.Ar perm ,
d7ba284c
KB
129for which the corresponding bit in the file mode creation mask
130is clear, is set.
131Otherwise, the mode bits represented by the specified
b5dc1377 132.Ar who
6aa2c2f8 133and
b5dc1377 134.Ar perm
d7ba284c 135values are set.
7bcabb1e 136.It \&\-
6aa2c2f8 137If no value is supplied for
b5dc1377 138.Ar perm ,
7bcabb1e 139the ``\-'' operation has no effect.
d7ba284c 140If no value is supplied for
b5dc1377 141.Ar who ,
d7ba284c 142the mode bits represented by
b5dc1377 143.Ar perm
d7ba284c
KB
144are cleared for the owner, group and other permissions.
145Otherwise, the mode bits represented by the specified
b5dc1377 146.Ar who
6aa2c2f8 147and
b5dc1377 148.Ar perm
d7ba284c 149values are cleared.
7bcabb1e 150.It =
d7ba284c 151The mode bits specified by the
b5dc1377 152.Ar who
d7ba284c
KB
153value are cleared, or, if no who value is specified, the owner, group
154and other mode bits are cleared.
155Then, if no value is supplied for
b5dc1377 156.Ar who ,
d7ba284c 157each permission bit specified in
b5dc1377 158.Ar perm ,
d7ba284c
KB
159for which the corresponding bit in the file mode creation mask
160is clear, is set.
161Otherwise, the mode bits represented by the specified
b5dc1377 162.Ar who
6aa2c2f8 163and
b5dc1377 164.Ar perm
d7ba284c 165values are set.
7bcabb1e 166.El
b5dc1377 167.Pp
d7ba284c 168Each
b5dc1377 169.Ar clause
d7ba284c
KB
170specifies one or more operations to be performed on the mode
171bits, and each operation is applied to the mode bits in the
172order specified.
b5dc1377 173.Pp
d7ba284c
KB
174Operations upon the other permissions only (specified by the symbol
175``o'' by itself), in combination with the
b5dc1377 176.Ar perm
d7ba284c 177symbols ``s'' or ``t'', are ignored.
b5dc1377 178.Sh EXAMPLES
7bcabb1e
CL
179.Bl -tag -width "u=rwx,go=u-w" -compact
180.It Li 644
d7ba284c 181make a file readable by anyone and writable by the owner only.
7bcabb1e
CL
182.Pp
183.It Li go-w
6aa2c2f8 184deny write permission to group and others.
7bcabb1e
CL
185.Pp
186.It Li =rw,+X
d7ba284c
KB
187set the read and write permissions to the usual defaults, but
188retain any execute permissions that are currently set.
7bcabb1e
CL
189.Pp
190.It Li +X
d7ba284c
KB
191make a directory or file searchable/executable by everyone if it is
192already searchable/executable by anyone.
7bcabb1e
CL
193.Pp
194.It Li 755
195.It Li u=rwx,go=rx
196.It Li u=rwx,go=u-w
d7ba284c 197make a file readable/executable by everyone and writeable by the owner only.
7bcabb1e
CL
198.Pp
199.It Li go=
6aa2c2f8 200clear all mode bits for group and others.
7bcabb1e
CL
201.Pp
202.It Li g=u-w
89b2cc72 203set the group bits equal to the user bits, but clear the group write bit.
7bcabb1e 204.El
b5dc1377 205.Sh BUGS
6aa2c2f8 206There's no
b5dc1377 207.Ar perm
6aa2c2f8 208option for the naughty bits.
b5dc1377
CL
209.Sh SEE ALSO
210.Xr install 1 ,
211.Xr chmod 2 ,
b5dc1377
CL
212.Xr stat 2 ,
213.Xr umask 2 ,
7f58c379 214.Xr fts 3 ,
b5dc1377
CL
215.Xr setmode 3 ,
216.Xr chown 8
217.Sh STANDARDS
6aa2c2f8 218The
b5dc1377 219.Nm chmod
5325ced3 220utility is expected to be POSIX 1003.2 compatible with the exception
6aa2c2f8 221of the
b5dc1377 222.Ar perm
7bcabb1e
CL
223symbols
224.Dq t
225and
226.Dq X
227which are not included in that standard.