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