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