file_cmds-220.4.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 July 08, 2004
39 .Dt CHMOD 1
40 .Os
41 .Sh NAME
42 .Nm chmod
43 .Nd change file modes or Access Control Lists
44 .Sh SYNOPSIS
45 .Nm chmod
46 .Op Fl fv
47 .Op Fl R Op Fl H | L | P
48 .Ar mode
49 .Ar
50 .Nm chmod
51 .Op Fl fv
52 .Op Fl R Op Fl H | L | P 
53 .Op -a | +a | =a
54 .Ar ACE
55 .Ar
56 .Nm chmod
57 .Op Fl fhv
58 .Op Fl R Op Fl H | L | P 
59 .Op Fl E
60 .Ar
61 .Nm chmod
62 .Op Fl fhv
63 .Op Fl R Op Fl H | L | P 
64 .Op Fl C
65 .Ar
66 .Nm chmod
67 .Op Fl fhv
68 .Op Fl R Op Fl H | L | P 
69 .Op Fl N
70 .Ar
71 .Sh DESCRIPTION
72 The
73 .Nm chmod
74 utility modifies the file mode bits of the listed files
75 as specified by the
76 .Ar mode
77 operand. It may also be used to modify the Access Control
78 Lists (ACLs) associated with the listed files.
79 .Pp
80 The generic options are as follows:
81 .Bl -tag -width Ds
82 .It Fl f
83 Do not display a diagnostic message if
84 .Nm chmod
85 could not modify the mode for
86 .Va file .
87 .It Fl H
88 If the
89 .Fl R
90 option is specified, symbolic links on the command line are followed.
91 (Symbolic links encountered in the tree traversal are not followed by
92 default.)
93 .It Fl h
94 If the file is a symbolic link, change the mode of the link itself
95 rather than the file that the link points to.
96 .It Fl L
97 If the
98 .Fl R
99 option is specified, all symbolic links are followed.
100 .It Fl P
101 If the
102 .Fl R
103 option is specified, no symbolic links are followed.
104 This is the default.
105 .It Fl R
106 Change the modes of the file hierarchies rooted in the files
107 instead of just the files themselves.
108 .It Fl v
109 Cause
110 .Nm chmod
111 to be verbose, showing filenames as the mode is modified.
112 If the
113 .Fl v
114 flag is specified more than once, the old and new modes of the file
115 will also be printed, in both octal and symbolic notation.
116 .El
117 .Pp
118 The
119 .Fl H ,
120 .Fl L
121 and
122 .Fl P
123 options are ignored unless the
124 .Fl R
125 option is specified.
126 In addition, these options override each other and the
127 command's actions are determined by the last one specified.
128 .Pp
129 Only the owner of a file or the super-user is permitted to change
130 the mode of a file.
131 .Sh DIAGNOSTICS
132 .Ex -std
133 .Sh MODES
134 Modes may be absolute or symbolic.
135 An absolute mode is an octal number constructed from the sum of
136 one or more of the following values:
137 .Pp
138 .Bl -tag -width 6n -compact -offset indent
139 .It Li 4000
140 (the set-user-ID-on-execution bit) Executable files with this bit set
141 will run with effective uid set to the uid of the file owner.
142 Directories with the set-user-id bit set will force all files and
143 sub-directories created in them to be owned by the directory owner
144 and not by the uid of the creating process, if the underlying file
145 system supports this feature: see
146 .Xr chmod 2
147 and the
148 .Ar suiddir
149 option to
150 .Xr mount 8 .
151 .It Li 2000
152 (the set-group-ID-on-execution bit) Executable files with this bit set
153 will run with effective gid set to the gid of the file owner.
154 .It Li 1000
155 (the sticky bit)
156 See
157 .Xr chmod 2
158 and
159 .Xr sticky 8 .
160 .It Li 0400
161 Allow read by owner.
162 .It Li 0200
163 Allow write by owner.
164 .It Li 0100
165 For files, allow execution by owner.
166 For directories, allow the owner to
167 search in the directory.
168 .It Li 0040
169 Allow read by group members.
170 .It Li 0020
171 Allow write by group members.
172 .It Li 0010
173 For files, allow execution by group members.
174 For directories, allow
175 group members to search in the directory.
176 .It Li 0004
177 Allow read by others.
178 .It Li 0002
179 Allow write by others.
180 .It Li 0001
181 For files, allow execution by others.
182 For directories allow others to
183 search in the directory.
184 .El
185 .Pp
186 For example, the absolute mode that permits read, write and execute by
187 the owner, read and execute by group members, read and execute by
188 others, and no set-uid or set-gid behaviour is 755
189 (400+200+100+040+010+004+001).
190 .Pp
191 The symbolic mode is described by the following grammar:
192 .Bd -literal -offset indent
193 mode         ::= clause [, clause ...]
194 clause       ::= [who ...] [action ...] action
195 action       ::= op [perm ...]
196 who          ::= a | u | g | o
197 op           ::= + | \- | =
198 perm         ::= r | s | t | w | x | X | u | g | o
199 .Ed
200 .Pp
201 The
202 .Ar who
203 symbols ``u'', ``g'', and ``o'' specify the user, group, and other parts
204 of the mode bits, respectively.
205 The
206 .Ar who
207 symbol ``a'' is equivalent to ``ugo''.
208 .Pp
209 The
210 .Ar perm
211 symbols represent the portions of the mode bits as follows:
212 .Pp
213 .Bl -tag -width Ds -compact -offset indent
214 .It r
215 The read bits.
216 .It s
217 The set-user-ID-on-execution and set-group-ID-on-execution bits.
218 .It t
219 The sticky bit.
220 .It w
221 The write bits.
222 .It x
223 The execute/search bits.
224 .It X
225 The execute/search bits if the file is a directory or any of the
226 execute/search bits are set in the original (unmodified) mode.
227 Operations with the
228 .Ar perm
229 symbol ``X'' are only meaningful in conjunction with the
230 .Ar op
231 symbol ``+'', and are ignored in all other cases.
232 .It u
233 The user permission bits in the original mode of the file.
234 .It g
235 The group permission bits in the original mode of the file.
236 .It o
237 The other permission bits in the original mode of the file.
238 .El
239 .Pp
240 The
241 .Ar op
242 symbols represent the operation performed, as follows:
243 .Bl -tag -width 4n
244 .It +
245 If no value is supplied for
246 .Ar perm ,
247 the ``+'' operation has no effect.
248 If no value is supplied for
249 .Ar who ,
250 each permission bit specified in
251 .Ar perm ,
252 for which the corresponding bit in the file mode creation mask
253 is clear, is set.
254 Otherwise, the mode bits represented by the specified
255 .Ar who
256 and
257 .Ar perm
258 values are set.
259 .It \&\-
260 If no value is supplied for
261 .Ar perm ,
262 the ``\-'' operation has no effect.
263 If no value is supplied for
264 .Ar who ,
265 each permission bit specified in
266 .Ar perm ,
267 for which the corresponding bit in the file mode creation mask
268 is clear, is cleared.
269 Otherwise, the mode bits represented by the specified
270 .Ar who
271 and
272 .Ar perm
273 values are cleared.
274 .It =
275 The mode bits specified by the
276 .Ar who
277 value are cleared, or, if no who value is specified, the owner, group
278 and other mode bits are cleared.
279 Then, if no value is supplied for
280 .Ar who ,
281 each permission bit specified in
282 .Ar perm ,
283 for which the corresponding bit in the file mode creation mask
284 is clear, is set.
285 Otherwise, the mode bits represented by the specified
286 .Ar who
287 and
288 .Ar perm
289 values are set.
290 .El
291 .Pp
292 Each
293 .Ar clause
294 specifies one or more operations to be performed on the mode
295 bits, and each operation is applied to the mode bits in the
296 order specified.
297 .Pp
298 Operations upon the other permissions only (specified by the symbol
299 ``o'' by itself), in combination with the
300 .Ar perm
301 symbols ``s'' or ``t'', are ignored.
302 .Sh EXAMPLES OF VALID MODES
303 .Bl -tag -width "u=rwx,go=u-w" -compact
304 .It Li 644
305 make a file readable by anyone and writable by the owner only.
306 .Pp
307 .It Li go-w
308 deny write permission to group and others.
309 .Pp
310 .It Li =rw,+X
311 set the read and write permissions to the usual defaults, but
312 retain any execute permissions that are currently set.
313 .Pp
314 .It Li +X
315 make a directory or file searchable/executable by everyone if it is
316 already searchable/executable by anyone.
317 .Pp
318 .It Li 755
319 .It Li u=rwx,go=rx
320 .It Li u=rwx,go=u-w
321 make a file readable/executable by everyone and writable by the owner only.
322 .Pp
323 .It Li go=
324 clear all mode bits for group and others.
325 .Pp
326 .It Li g=u-w
327 set the group bits equal to the user bits, but clear the group write bit.
328 .El
329 .Sh ACL MANIPULATION OPTIONS
330 ACLs are manipulated using extensions to the symbolic mode
331 grammar.  Each file has one ACL, containing an ordered list of entries.
332 Each entry refers to a user or group, and grants or denies a set of
333 permissions.
334 In cases where a user and a group exist with the same name, the
335 user/group name can be prefixed with "user:" or "group:" in order to
336 specify the type of name.
337 .Pp
338 If the user or group name contains spaces you can use ':' as the delimiter
339 between name and permission.
340 .Pp
341 The following permissions are applicable to all filesystem objects:
342 .Bl -tag -width 6n -compact -offset indent
343 .It delete
344 Delete the item.  Deletion may be granted by either this permission
345 on an object or the delete_child right on the containing directory.
346 .It readattr
347 Read an objects basic attributes.  This is implicitly granted if 
348 the object can be looked up and not explicitly denied.
349 .It writeattr
350 Write an object's basic attributes.
351 .It readextattr
352 Read extended attributes.
353 .It writeextattr
354 Write extended attributes.
355 .It readsecurity
356 Read an object's extended security information (ACL).
357 .It writesecurity
358 Write an object's security information (ownership, mode, ACL).
359 .It chown
360 Change an object's ownership.
361 .El
362 .Pp
363 The following permissions are applicable to directories:
364 .Bl -tag -width 6n -compact -offset indent
365 .It list
366 List entries.
367 .It search
368 Look up files by name.
369 .It add_file
370 Add a file.
371 .It add_subdirectory
372 Add a subdirectory.
373 .It delete_child
374 Delete a contained object.  See the file delete permission above.
375 .El
376 .Pp
377 The following permissions are applicable to non-directory filesystem objects:
378 .Bl -tag -width 6n -compact -offset indent
379 .It read
380 Open for reading.
381 .It write
382 Open for writing.
383 .It append
384 Open for writing, but in a fashion that only allows writes into areas of 
385 the file not previously written.
386 .It execute
387 Execute the file as a script or program.
388 .El
389 .Pp
390 ACL inheritance is controlled with the following permissions words, which
391 may only be applied to directories:
392 .Bl -tag -width 6n -compact -offset indent
393 .It file_inherit
394 Inherit to files.
395 .It directory_inherit
396 Inherit to directories.
397 .It limit_inherit
398 This flag is only relevant to entries inherited by subdirectories; it
399 causes the directory_inherit flag to be cleared in the entry that is
400 inherited, preventing further nested subdirectories from also
401 inheriting the entry.
402 .It only_inherit
403 The entry is inherited by created items but not considered when processing
404 the ACL.
405 .El
406 .Pp
407 The ACL manipulation options are as follows:
408 .Bl -tag -width Ds
409 .It \fB+a\fR
410 The +a mode parses a new ACL entry from the next argument on
411 the commandline and inserts it into the canonical location in the
412 ACL. If the supplied entry refers to an identity already listed, the
413 two entries are combined.
414 .Pp
415 \fBExamples\fR
416  # ls -le
417  -rw-r--r--+ 1 juser  wheel  0 Apr 28 14:06 file1
418  # chmod +a "admin allow write" file1
419  # ls -le
420  -rw-r--r--+ 1 juser  wheel  0 Apr 28 14:06 file1
421    owner: juser
422    1: admin allow write
423  # chmod +a "guest deny read" file1
424  # ls -le
425  -rw-r--r--+ 1 juser  wheel  0 Apr 28 14:06 file1
426    owner: juser
427    1: guest deny read
428    2: admin allow write
429  # chmod +a "admin allow delete" file1
430  # ls -le
431  -rw-r--r--+ 1 juser  wheel  0 Apr 28 14:06 file1
432    owner: juser
433    1: guest deny read
434    2: admin allow write,delete
435  # chmod +a "User 1:allow:read" file
436  # ls -le
437  -rw-r--r--+ 1 juser  wheel  0 Apr 28 14:06 file1
438    owner: juser
439    1: guest deny read
440    2: User 1 allow read
441    3: admin allow write,delete
442 .Pp
443 The +a mode strives to maintain correct canonical form for the ACL.
444                  local deny
445                  local allow
446                  inherited deny
447                  inherited allow
448 .Pp
449 By default, chmod adds entries to the top of the local deny and local
450 allow lists. Inherited entries are added by using the +ai mode.
451 .Pp
452 \fBExamples\fR
453  # ls -le
454  -rw-r--r--+ 1 juser  wheel  0 Apr 28 14:06 file1
455    owner: juser
456    1: guest deny read
457    2: admin allow write,delete
458    3: juser inherited deny delete
459    4: admin inherited allow delete
460    5: backup inherited deny read
461    6: admin inherited allow write-security
462  # chmod +ai "others allow read" file1
463  # ls -le
464  -rw-r--r--+ 1 juser  wheel  0 Apr 28 14:06 file1
465    owner: juser
466    1: guest deny read
467    2: admin allow write,delete
468    3: juser inherited deny delete
469    4: others inherited allow read
470    5: admin inherited allow delete
471    6: backup inherited deny read
472    7: admin inherited allow write-security
473 .It \fB+a#\fR
474 When a specific ordering is required, the exact location at which an
475 entry will be inserted is specified with the +a# mode.
476 .Pp
477 \fBExamples\fR
478  # ls -le
479  -rw-r--r--+ 1 juser  wheel  0 Apr 28 14:06 file1
480    owner: juser
481    1: guest deny read
482    2: admin allow write
483  # chmod +a# 2 "others deny read" file1
484  # ls -le
485  -rw-r--r--+ 1 juser  wheel  0 Apr 28 14:06 file1
486    owner: juser
487    1: guest deny read
488    2: others deny read
489    3: admin allow write
490 .Pp
491 The +ai# mode may be used to insert inherited entries at a specific
492 location. Note that these modes allow non-canonical ACL ordering to
493 be constructed.
494 .It Fl a
495 The -a mode is used to delete ACL entries. All entries exactly
496 matching the supplied entry will be deleted. If the entry lists a
497 subset of rights granted by an entry, only the rights listed are
498 removed. Entries may also be deleted by index using the -a# mode.
499 .Pp
500 \fBExamples\fR
501  # ls -le
502  -rw-r--r--+ 1 juser  wheel  0 Apr 28 14:06 file1
503    owner: juser
504    1: guest deny read
505    2: admin allow write,delete
506  # chmod -a# 1 file1
507  # ls -le
508  -rw-r--r--+ 1 juser  wheel  0 Apr 28 14:06 file1
509    owner: juser
510    1: admin allow write,delete
511  # chmod -a "admin allow write" file1
512  # ls -le
513  -rw-r--r--+ 1 juser  wheel  0 Apr 28 14:06 file1
514    owner: juser
515    1: admin allow delete
516 .Pp
517 Inheritance is not considered when processing the -a mode; rights and
518 entries will be removed regardless of their inherited state.
519 .Pp
520 If the user or group name contains spaces you can use ':' as the delimiter
521 .Pp
522 \fBExample\fR
523  # chmod +a "User 1:allow:read" file
524 .It \fB=a#\fR
525 Individual entries are rewritten using the =a# mode.
526 .Pp
527 \fBExamples\fR
528  # ls -le
529  -rw-r--r--+ 1 juser  wheel  0 Apr 28 14:06 file1
530    owner: juser
531    1: admin allow delete
532  # chmod =a# 1 "admin allow write,chown"
533  # ls -le
534  -rw-r--r--+ 1 juser  wheel  0 Apr 28 14:06 file1
535    owner: juser
536    1: admin allow write,chown
537 .Pp
538 This mode may not be used to add new entries.
539 .It Fl E    
540 Reads the ACL information from stdin, as a sequential list
541 of ACEs, separated by newlines.  If the information parses correctly,
542 the existing information is replaced.
543 .It Fl C
544 Returns false if any of the named files have ACLs in non-canonical order.
545 .It Fl i
546 Removes the 'inherited' bit from all entries in the named file(s) ACLs.
547 .It Fl I
548 Removes all inherited entries from the named file(s) ACL(s).
549 .It Fl N
550 Removes the ACL from the named file(s).
551 .El
552 .Sh COMPATIBILITY
553 The
554 .Fl v
555 option is non-standard and its use in scripts is not recommended.
556 .Sh SEE ALSO
557 .Xr chflags 1 ,
558 .Xr fsaclctl 1 ,
559 .Xr install 1 ,
560 .Xr chmod 2 ,
561 .Xr stat 2 ,
562 .Xr umask 2 ,
563 .Xr fts 3 ,
564 .Xr setmode 3 ,
565 .Xr symlink 7 ,
566 .Xr chown 8 ,
567 .Xr mount 8 ,
568 .Xr sticky 8
569 .Sh STANDARDS
570 The
571 .Nm chmod
572 utility is expected to be
573 .St -p1003.2
574 compatible with the exception of the
575 .Ar perm
576 symbol
577 .Dq t
578 which is not included in that standard.
579 .Sh HISTORY
580 A
581 .Nm chmod
582 command appeared in
583 .At v1 .