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