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