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