xref: /dragonfly/bin/chmod/chmod.1 (revision c59f969a)
1.\"-
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.
16.\" 3. Neither the name of the University nor the names of its contributors
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
33.\" $FreeBSD: head/bin/chmod/chmod.1 282208 2015-04-29 00:49:00Z smh $
34.\"
35.Dd May 11, 2016
36.Dt CHMOD 1
37.Os
38.Sh NAME
39.Nm chmod
40.Nd change file modes
41.Sh SYNOPSIS
42.Nm
43.Op Fl fhv
44.Op Fl R Op Fl H | L | P
45.Ar mode
46.Ar
47.Sh DESCRIPTION
48The
49.Nm
50utility modifies the file mode bits of the listed files
51as specified by the
52.Ar mode
53operand.
54.Pp
55The options are as follows:
56.Bl -tag -width indent
57.It Fl f
58Do not display a diagnostic message if
59.Nm
60could not modify the mode for
61.Va file ,
62nor modify the exit status to reflect such failures.
63.It Fl H
64If the
65.Fl R
66option is specified, symbolic links on the command line are followed
67and hence unaffected by the command.
68(Symbolic links encountered during tree traversal are not followed.)
69.It Fl h
70If the file is a symbolic link, change the mode of the link itself
71rather than the file that the link points to.
72.It Fl L
73If the
74.Fl R
75option is specified, all symbolic links are followed.
76.It Fl P
77If the
78.Fl R
79option is specified, no symbolic links are followed.
80This is the default.
81.It Fl R
82Change the modes of the file hierarchies rooted in the files,
83instead of just the files themselves.
84Beware of unintentionally matching the
85.Dq Pa ".."
86hard link to the parent directory when using wildcards like
87.Dq Li ".*" .
88.It Fl v
89Cause
90.Nm
91to be verbose, showing filenames as the mode is modified.
92If the
93.Fl v
94flag is specified more than once, the old and new modes of the file
95will also be printed, in both octal and symbolic notation.
96.El
97.Pp
98The
99.Fl H ,
100.Fl L
101and
102.Fl P
103options are ignored unless the
104.Fl R
105option is specified.
106In addition, these options override each other and the
107command's actions are determined by the last one specified.
108.Pp
109Only the owner of a file or the super-user is permitted to change
110the mode of a file.
111.Sh EXIT STATUS
112.Ex -std
113.Sh MODES
114Modes may be absolute or symbolic.
115An absolute mode is an octal number constructed from the sum of
116one or more of the following values:
117.Pp
118.Bl -tag -width 6n -compact -offset indent
119.It Li 4000
120(the setuid bit).
121Executable files with this bit set
122will run with effective uid set to the uid of the file owner.
123Directories with this bit set will force all files and
124sub-directories created in them to be owned by the directory owner
125and not by the uid of the creating process, if the underlying file
126system supports this feature: see
127.Xr chmod 2
128and the
129.Cm suiddir
130option to
131.Xr mount 8 .
132.It Li 2000
133(the setgid bit).
134Executable files with this bit set
135will run with effective gid set to the gid of the file owner.
136.It Li 1000
137(the sticky bit).
138See
139.Xr chmod 2
140and
141.Xr sticky 8 .
142.It Li 0400
143Allow read by owner.
144.It Li 0200
145Allow write by owner.
146.It Li 0100
147For files, allow execution by owner.
148For directories, allow the owner to
149search in the directory.
150.It Li 0040
151Allow read by group members.
152.It Li 0020
153Allow write by group members.
154.It Li 0010
155For files, allow execution by group members.
156For directories, allow
157group members to search in the directory.
158.It Li 0004
159Allow read by others.
160.It Li 0002
161Allow write by others.
162.It Li 0001
163For files, allow execution by others.
164For directories allow others to
165search in the directory.
166.El
167.Pp
168For example, the absolute mode that permits read, write and execute by
169the owner, read and execute by group members, read and execute by
170others, and no set-uid or set-gid behaviour is 755
171(400+200+100+040+010+004+001).
172.Pp
173The symbolic mode is described by the following grammar:
174.Bd -literal -offset indent
175mode         ::= clause [, clause ...]
176clause       ::= [who ...] [action ...] action
177action       ::= op [perm ...]
178who          ::= a | u | g | o
179op           ::= + | \- | =
180perm         ::= r | s | t | w | x | X | u | g | o
181.Ed
182.Pp
183The
184.Ar who
185symbols ``u'', ``g'', and ``o'' specify the user, group, and other parts
186of the mode bits, respectively.
187The
188.Ar who
189symbol ``a'' is equivalent to ``ugo''.
190.Pp
191The
192.Ar perm
193symbols represent the portions of the mode bits as follows:
194.Pp
195.Bl -tag -width Ds -compact -offset indent
196.It r
197The read bits.
198.It s
199The set-user-ID-on-execution and set-group-ID-on-execution bits.
200.It t
201The sticky bit.
202.It w
203The write bits.
204.It x
205The execute/search bits.
206.It X
207The execute/search bits if the file is a directory or any of the
208execute/search bits are set in the original (unmodified) mode.
209Operations with the
210.Ar perm
211symbol ``X'' are only meaningful in conjunction with the
212.Ar op
213symbol ``+'', and are ignored in all other cases.
214.It u
215The user permission bits in the original mode of the file.
216.It g
217The group permission bits in the original mode of the file.
218.It o
219The other permission bits in the original mode of the file.
220.El
221.Pp
222The
223.Ar op
224symbols represent the operation performed, as follows:
225.Bl -tag -width 4n
226.It +
227If no value is supplied for
228.Ar perm ,
229the ``+'' operation has no effect.
230If no value is supplied for
231.Ar who ,
232each permission bit specified in
233.Ar perm ,
234for which the corresponding bit in the file mode creation mask
235(see
236.Xr umask 2 )
237is clear, is set.
238Otherwise, the mode bits represented by the specified
239.Ar who
240and
241.Ar perm
242values are set.
243.It \&\-
244If no value is supplied for
245.Ar perm ,
246the ``\-'' operation has no effect.
247If no value is supplied for
248.Ar who ,
249each permission bit specified in
250.Ar perm ,
251for which the corresponding bit in the file mode creation mask
252is clear, is cleared.
253Otherwise, the mode bits represented by the specified
254.Ar who
255and
256.Ar perm
257values are cleared.
258.It =
259The mode bits specified by the
260.Ar who
261value are cleared, or, if no
262.Ar who
263value is specified, the owner, group
264and other mode bits are cleared.
265Then, if no value is supplied for
266.Ar who ,
267each permission bit specified in
268.Ar perm ,
269for which the corresponding bit in the file mode creation mask
270is clear, is set.
271Otherwise, the mode bits represented by the specified
272.Ar who
273and
274.Ar perm
275values are set.
276.El
277.Pp
278Each
279.Ar clause
280specifies one or more operations to be performed on the mode
281bits, and each operation is applied to the mode bits in the
282order specified.
283.Pp
284Operations upon the other permissions only (specified by the symbol
285``o'' by itself), in combination with the
286.Ar perm
287symbols ``s'' or ``t'', are ignored.
288.Pp
289The ``w'' permission on directories will permit file creation, relocation,
290and copy into that directory.
291Files created within the directory itself will inherit its group ID.
292.Sh EXAMPLES
293.Bl -tag -width "u=rwx,go=u-w" -compact
294.It Li 644
295make a file readable by anyone and writable by the owner only.
296.Pp
297.It Li go-w
298deny write permission to group and others.
299.Pp
300.It Li =rw,+X
301set the read and write permissions to the usual defaults, but
302retain any execute permissions that are currently set.
303.Pp
304.It Li +X
305make a directory or file searchable/executable by everyone if it is
306already searchable/executable by anyone.
307.Pp
308.It Li 755
309.It Li u=rwx,go=rx
310.It Li u=rwx,go=u-w
311make a file readable/executable by everyone and writable by the owner only.
312.Pp
313.It Li go=
314clear all mode bits for group and others.
315.Pp
316.It Li g=u-w
317set the group bits equal to the user bits, but clear the group write bit.
318.El
319.Sh COMPATIBILITY
320The
321.Fl v
322option is non-standard and its use in scripts is not recommended.
323.Sh SEE ALSO
324.Xr chflags 1 ,
325.Xr install 1 ,
326.Xr chmod 2 ,
327.Xr stat 2 ,
328.Xr umask 2 ,
329.Xr fts 3 ,
330.Xr setmode 3 ,
331.Xr symlink 7 ,
332.Xr chown 8 ,
333.Xr mount 8 ,
334.Xr sticky 8
335.Sh STANDARDS
336The
337.Nm
338utility is expected to be
339.St -p1003.2
340compatible with the exception of the
341.Ar perm
342symbol
343.Dq t
344which is not included in that standard.
345.Sh HISTORY
346A
347.Nm
348command appeared in
349.At v1 .
350.Sh BUGS
351There is no
352.Ar perm
353option for the naughty bits of a horse.
354