file_cmds-45.tar.gz
[apple/file_cmds.git] / chmod / chmod.1
1 .\"     $NetBSD: chmod.1,v 1.11 1997/10/20 08:51:10 enami Exp $
2 .\"
3 .\" Copyright (c) 1989, 1990, 1993, 1994
4 .\"     The Regents of the University of California.  All rights reserved.
5 .\"
6 .\" This code is derived from software contributed to Berkeley by
7 .\" the Institute of Electrical and Electronics Engineers, Inc.
8 .\"
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
11 .\" are met:
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\"    notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\"    notice, this list of conditions and the following disclaimer in the
16 .\"    documentation and/or other materials provided with the distribution.
17 .\" 3. All advertising materials mentioning features or use of this software
18 .\"    must display the following acknowledgement:
19 .\"     This product includes software developed by the University of
20 .\"     California, Berkeley and its contributors.
21 .\" 4. Neither the name of the University nor the names of its contributors
22 .\"    may be used to endorse or promote products derived from this software
23 .\"    without specific prior written permission.
24 .\"
25 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 .\" SUCH DAMAGE.
36 .\"
37 .\"     @(#)chmod.1     8.4 (Berkeley) 3/31/94
38 .\"
39 .Dd March 31, 1994
40 .Dt CHMOD 1
41 .Os
42 .Sh NAME
43 .Nm chmod
44 .Nd change file modes
45 .Sh SYNOPSIS
46 .Nm
47 .Oo
48 .Fl R
49 .Op Fl H | Fl L | Fl P
50 .Oc
51 .Op Fl h
52 .Ar mode
53 .Ar file ...
54 .Sh DESCRIPTION
55 The
56 .Nm
57 utility modifies the file mode bits of the listed files
58 as specified by the
59 .Ar mode
60 operand.
61 .Pp
62 The options are as follows:
63 .Bl -tag -width Ds
64 .It Fl H
65 If the
66 .Fl R
67 option is specified, symbolic links on the command line are followed.
68 (Symbolic links encountered in the tree traversal are not followed.)
69 .It Fl L
70 If the
71 .Fl R
72 option is specified, all symbolic links are followed.
73 .It Fl P
74 If the
75 .Fl R
76 option is specified, no symbolic links are followed.
77 .It Fl R
78 Change the modes of the file hierarchies rooted in the files
79 instead of just the files themselves.
80 .\" .It Fl h
81 .\" If
82 .\" .Ar file
83 .\" is symbolic link, the mode of the link is changed.
84 .El
85 .Pp
86 .\" If the option
87 .\" .Fl h
88 .\" is not given,
89 Unless the
90 .Fl H
91 or
92 .Fl L
93 option is set,
94 .Nm
95 on a symbolic link always succeeds and has no effect.
96 The
97 .Fl H ,
98 .Fl L
99 and
100 .Fl P
101 options are ignored unless the
102 .Fl R
103 option is specified.
104 In addition, these options override each other and the
105 command's actions are determined by the last one specified.
106 .Pp
107 Only the owner of a file or the super-user is permitted to change
108 the mode of a file.
109 .Pp
110 The
111 .Nm
112 utility exits 0 on success, and >0 if an error occurs.
113 .Sh MODES
114 Modes may be absolute or symbolic.
115 An absolute mode is an octal number constructed by
116 .Ar or-ing
117 the following values:
118 .Pp
119 .Bl -tag -width 6n -compact -offset indent
120 .It Li 4000
121 set-user-ID-on-execution
122 .It Li 2000
123 set-group-ID-on-execution
124 .It Li 1000
125 sticky bit, see
126 .Xr chmod 2
127 .It Li 0400
128 read by owner
129 .It Li 0200
130 write by owner
131 .It Li 0100
132 execute (or search for directories) by owner
133 .It Li 0070
134 read, write, execute/search by group
135 .It Li 0007
136 read, write, execute/search by others
137 .El
138 .Pp
139 The read, write, and execute/search values for group and others
140 are encoded as described for owner.
141 .Pp
142 The symbolic mode is described by the following grammar:
143 .Bd -literal -offset indent
144 mode         ::= clause [, clause ...]
145 clause       ::= [who ...] [action ...] last_action
146 action       ::= op [perm ...]
147 last_action  ::= op [perm ...]
148 who          ::= a | u | g | o
149 op           ::= + | \- | =
150 perm         ::= r | s | t | w | x | X | u | g | o
151 .Ed
152 .Pp
153 The
154 .Ar who
155 symbols ``u'', ``g'', and ``o'' specify the user, group, and other parts
156 of the mode bits, respectively.
157 The
158 .Ar who
159 symbol ``a'' is equivalent to ``ugo''.
160 .Pp
161 .ne 1i
162 The
163 .Ar perm
164 symbols represent the portions of the mode bits as follows:
165 .Pp
166 .Bl -tag -width Ds -compact -offset indent
167 .It r
168 The read bits.
169 .It s
170 The set-user-ID-on-execution and set-group-ID-on-execution bits.
171 .It t
172 The sticky bit.
173 .It w
174 The write bits.
175 .It x
176 The execute/search bits.
177 .It X
178 The execute/search bits if the file is a directory or any of the
179 execute/search bits are set in the original (unmodified) mode.
180 Operations with the
181 .Ar perm
182 symbol ``X'' are only meaningful in conjunction with the
183 .Ar op
184 symbol ``+'', and are ignored in all other cases.
185 .It u
186 The user permission bits in the mode of the original file.
187 .It g
188 The group permission bits in the mode of the original file.
189 .It o
190 The other permission bits in the mode of the original file.
191 .El
192 .Pp
193 The
194 .Ar op
195 symbols represent the operation performed, as follows:
196 .Bl -tag -width 4n
197 .It +
198 If no value is supplied for
199 .Ar perm ,
200 the ``+'' operation has no effect.
201 If no value is supplied for
202 .Ar who ,
203 each permission bit specified in
204 .Ar perm ,
205 for which the corresponding bit in the file mode creation mask
206 is clear, is set.
207 Otherwise, the mode bits represented by the specified
208 .Ar who
209 and
210 .Ar perm
211 values are set.
212 .It \&\-
213 If no value is supplied for
214 .Ar perm ,
215 the ``\-'' operation has no effect.
216 If no value is supplied for
217 .Ar who ,
218 each permission bit specified in
219 .Ar perm ,
220 for which the corresponding bit in the file mode creation mask
221 is clear, is cleared.
222 Otherwise, the mode bits represented by the specified
223 .Ar who
224 and
225 .Ar perm
226 values are cleared.
227 .It =
228 The mode bits specified by the
229 .Ar who
230 value are cleared, or, if no who value is specified, the owner, group
231 and other mode bits are cleared.
232 Then, if no value is supplied for
233 .Ar who ,
234 each permission bit specified in
235 .Ar perm ,
236 for which the corresponding bit in the file mode creation mask
237 is clear, is set.
238 Otherwise, the mode bits represented by the specified
239 .Ar who
240 and
241 .Ar perm
242 values are set.
243 .El
244 .Pp
245 Each
246 .Ar clause
247 specifies one or more operations to be performed on the mode
248 bits, and each operation is applied to the mode bits in the
249 order specified.
250 .Pp
251 Operations upon the other permissions only (specified by the symbol
252 ``o'' by itself), in combination with the
253 .Ar perm
254 symbols ``s'' or ``t'', are ignored.
255 .Sh EXAMPLES
256 .Bl -tag -width "u=rwx,go=u-w" -compact
257 .It Li 644
258 make a file readable by anyone and writable by the owner only.
259 .Pp
260 .It Li go-w
261 deny write permission to group and others.
262 .Pp
263 .It Li =rw,+X
264 set the read and write permissions to the usual defaults, but
265 retain any execute permissions that are currently set.
266 .Pp
267 .It Li +X
268 make a directory or file searchable/executable by everyone if it is
269 already searchable/executable by anyone.
270 .Pp
271 .It Li 755
272 .It Li u=rwx,go=rx
273 .It Li u=rwx,go=u-w
274 make a file readable/executable by everyone and writable by the owner only.
275 .Pp
276 .It Li go=
277 clear all mode bits for group and others.
278 .Pp
279 .It Li g=u-w
280 set the group bits equal to the user bits, but clear the group write bit.
281 .El
282 .Sh BUGS
283 There's no
284 .Ar perm
285 option for the naughty bits.
286 .Sh SEE ALSO
287 .Xr install 1 ,
288 .Xr chmod 2 ,
289 .Xr stat 2 ,
290 .Xr umask 2 ,
291 .Xr fts 3 ,
292 .Xr setmode 3 ,
293 .Xr symlink 7 ,
294 .Xr chown 8
295 .Sh STANDARDS
296 The
297 .Nm
298 utility is expected to be
299 .St -p1003.2
300 compatible with the exception of the
301 .Ar perm
302 symbols
303 .Dq t
304 and
305 .Dq X
306 which are not included in that standard.