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