xref: /freebsd/bin/chmod/chmod.1 (revision e627b39baccd1ec9129690167cf5e6d860509655)
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.\"	$Id: chmod.1,v 1.3 1996/02/16 00:08:53 joerg Exp $
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 chmod
46.Oo
47.Fl R
48.Op Fl H | Fl L | Fl P
49.Oc
50.Ar mode
51.Ar file ...
52.Sh DESCRIPTION
53The
54.Nm chmod
55utility modifies the file mode bits of the listed files
56as specified by the
57.Ar mode
58operand.
59.Pp
60The options are as follows:
61.Bl -tag -width Ds
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.)
67.It Fl L
68If the
69.Fl R
70option is specified, all symbolic links are followed.
71.It Fl P
72If the
73.Fl R
74option is specified, no symbolic links are followed.
75.It Fl R
76Change the modes of the file hierarchies rooted in the files
77instead of just the files themselves.
78.El
79.Pp
80Symbolic links do not have modes, so unless the
81.Fl H
82or
83.Fl L
84option is set,
85.Nm chmod
86on a symbolic link always succeeds and has no effect.
87The
88.Fl H ,
89.Fl L
90and
91.Fl P
92options are ignored unless the
93.Fl R
94option is specified.
95In addition, these options override each other and the
96command's actions are determined by the last one specified.
97.Pp
98Only the owner of a file or the super-user is permitted to change
99the mode of a file.
100.Pp
101The
102.Nm chmod
103utility exits 0 on success, and >0 if an error occurs.
104.Sh MODES
105Modes may be absolute or symbolic.
106An absolute mode is an octal number constructed by
107.Ar or-ing
108the following values:
109.Pp
110.Bl -tag -width 6n -compact -offset indent
111.It Li 4000
112set-user-ID-on-execution
113.It Li 2000
114set-group-ID-on-execution
115.It Li 1000
116sticky bit, see chmod(2)
117.It Li 0400
118read by owner
119.It Li 0200
120write by owner
121.It Li 0100
122execute (or search for directories) by owner
123.It Li 0070
124read, write, execute/search by group
125.It Li 0007
126read, write, execute/search by others
127.El
128.Pp
129The read, write, and execute/search values for group and others
130are encoded as described for owner.
131.Pp
132The symbolic mode is described by the following grammar:
133.Bd -literal -offset indent
134mode         ::= clause [, clause ...]
135clause       ::= [who ...] [action ...] last_action
136action       ::= op [perm ...]
137last_action  ::= op [perm ...]
138who          ::= a | u | g | o
139op           ::= + | \- | =
140perm         ::= r | s | t | w | x | X | u | g | o
141.Ed
142.Pp
143The
144.Ar who
145symbols ``u'', ``g'', and ``o'' specify the user, group, and other parts
146of the mode bits, respectively.
147The
148.Ar who
149symbol ``a'' is equivalent to ``ugo''.
150.Pp
151.ne 1i
152The
153.Ar perm
154symbols represent the portions of the mode bits as follows:
155.Pp
156.Bl -tag -width Ds -compact -offset indent
157.It r
158The read bits.
159.It s
160The set-user-ID-on-execution and set-group-ID-on-execution bits.
161.It t
162The sticky bit.
163.It w
164The write bits.
165.It x
166The execute/search bits.
167.It X
168The execute/search bits if the file is a directory or any of the
169execute/search bits are set in the original (unmodified) mode.
170Operations with the
171.Ar perm
172symbol ``X'' are only meaningful in conjunction with the
173.Ar op
174symbol ``+'', and are ignored in all other cases.
175.It u
176The user permission bits in the mode of the original file.
177.It g
178The group permission bits in the mode of the original file.
179.It o
180The other permission bits in the mode of the original file.
181.El
182.Pp
183The
184.Ar op
185symbols represent the operation performed, as follows:
186.Bl -tag -width 4n
187.It +
188If no value is supplied for
189.Ar perm ,
190the ``+'' operation has no effect.
191If no value is supplied for
192.Ar who ,
193each permission bit specified in
194.Ar perm ,
195for which the corresponding bit in the file mode creation mask
196is clear, is set.
197Otherwise, the mode bits represented by the specified
198.Ar who
199and
200.Ar perm
201values are set.
202.It \&\-
203If no value is supplied for
204.Ar perm ,
205the ``\-'' operation has no effect.
206If no value is supplied for
207.Ar who ,
208each permission bit specified in
209.Ar perm ,
210for which the corresponding bit in the file mode creation mask
211is clear, is cleared.
212Otherwise, the mode bits represented by the specified
213.Ar who
214and
215.Ar perm
216values are cleared.
217.It =
218The mode bits specified by the
219.Ar who
220value are cleared, or, if no who value is specified, the owner, group
221and other mode bits are cleared.
222Then, if no value is supplied for
223.Ar who ,
224each permission bit specified in
225.Ar perm ,
226for which the corresponding bit in the file mode creation mask
227is clear, is set.
228Otherwise, the mode bits represented by the specified
229.Ar who
230and
231.Ar perm
232values are set.
233.El
234.Pp
235Each
236.Ar clause
237specifies one or more operations to be performed on the mode
238bits, and each operation is applied to the mode bits in the
239order specified.
240.Pp
241Operations upon the other permissions only (specified by the symbol
242``o'' by itself), in combination with the
243.Ar perm
244symbols ``s'' or ``t'', are ignored.
245.Sh EXAMPLES
246.Bl -tag -width "u=rwx,go=u-w" -compact
247.It Li 644
248make a file readable by anyone and writable by the owner only.
249.Pp
250.It Li go-w
251deny write permission to group and others.
252.Pp
253.It Li =rw,+X
254set the read and write permissions to the usual defaults, but
255retain any execute permissions that are currently set.
256.Pp
257.It Li +X
258make a directory or file searchable/executable by everyone if it is
259already searchable/executable by anyone.
260.Pp
261.It Li 755
262.It Li u=rwx,go=rx
263.It Li u=rwx,go=u-w
264make a file readable/executable by everyone and writable by the owner only.
265.Pp
266.It Li go=
267clear all mode bits for group and others.
268.Pp
269.It Li g=u-w
270set the group bits equal to the user bits, but clear the group write bit.
271.El
272.Sh BUGS
273There's no
274.Ar perm
275option for the naughty bits.
276.Sh SEE ALSO
277.Xr chflags 1 ,
278.Xr install 1 ,
279.Xr chmod 2 ,
280.Xr stat 2 ,
281.Xr umask 2 ,
282.Xr fts 3 ,
283.Xr setmode 3 ,
284.Xr symlink 7 ,
285.Xr chown 8
286.Sh STANDARDS
287The
288.Nm chmod
289utility is expected to be POSIX 1003.2
290compatible with the exception of the
291.Ar perm
292symbols
293.Dq t
294and
295.Dq X
296which are not included in that standard.
297.Sh HISTORY
298A
299.Nm
300command appeared in
301.At v1 .
302