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