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