xref: /netbsd-src/bin/chmod/chmod.1 (revision fdecd6a253f999ae92b139670d9e15cc9df4497c)
1.\"	$NetBSD: chmod.1,v 1.9 1997/06/23 20:30:24 pk Exp $
2.\"
3.\" Copyright (c) 1989, 1990, 1993, 1994
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" the Institute of Electrical and Electronics Engineers, Inc.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"	This product includes software developed by the University of
20.\"	California, Berkeley and its contributors.
21.\" 4. Neither the name of the University nor the names of its contributors
22.\"    may be used to endorse or promote products derived from this software
23.\"    without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35.\" SUCH DAMAGE.
36.\"
37.\"	@(#)chmod.1	8.4 (Berkeley) 3/31/94
38.\"
39.Dd March 31, 1994
40.Dt CHMOD 1
41.Os
42.Sh NAME
43.Nm chmod
44.Nd change file modes
45.Sh SYNOPSIS
46.Nm chmod
47.Oo
48.Fl R
49.Op Fl H | Fl L | Fl P
50.Oc
51.Ar mode
52.Ar file ...
53.Sh DESCRIPTION
54The
55.Nm chmod
56utility modifies the file mode bits of the listed files
57as specified by the
58.Ar mode
59operand.
60.Pp
61The options are as follows:
62.Bl -tag -width Ds
63.It Fl H
64If the
65.Fl R
66option is specified, symbolic links on the command line are followed.
67(Symbolic links encountered in the tree traversal are not followed.)
68.It Fl L
69If the
70.Fl R
71option is specified, all symbolic links are followed.
72.It Fl P
73If the
74.Fl R
75option is specified, no symbolic links are followed.
76.It Fl R
77Change the modes of the file hierarchies rooted in the files
78instead of just the files themselves.
79.El
80.Pp
81Symbolic links do not have modes, so unless the
82.Fl H
83or
84.Fl L
85option is set,
86.Nm chmod
87on a symbolic link always succeeds and has no effect.
88The
89.Fl H ,
90.Fl L
91and
92.Fl P
93options are ignored unless the
94.Fl R
95option is specified.
96In addition, these options override each other and the
97command's actions are determined by the last one specified.
98.Pp
99Only the owner of a file or the super-user is permitted to change
100the mode of a file.
101.Pp
102The
103.Nm chmod
104utility exits 0 on success, and >0 if an error occurs.
105.Sh MODES
106Modes may be absolute or symbolic.
107An absolute mode is an octal number constructed by
108.Ar or-ing
109the following values:
110.Pp
111.Bl -tag -width 6n -compact -offset indent
112.It Li 4000
113set-user-ID-on-execution
114.It Li 2000
115set-group-ID-on-execution
116.It Li 1000
117sticky bit, see
118.Xr chmod 2
119.It Li 0400
120read by owner
121.It Li 0200
122write by owner
123.It Li 0100
124execute (or search for directories) by owner
125.It Li 0070
126read, write, execute/search by group
127.It Li 0007
128read, write, execute/search by others
129.El
130.Pp
131The read, write, and execute/search values for group and others
132are encoded as described for owner.
133.Pp
134The symbolic mode is described by the following grammar:
135.Bd -literal -offset indent
136mode         ::= clause [, clause ...]
137clause       ::= [who ...] [action ...] last_action
138action       ::= op [perm ...]
139last_action  ::= op [perm ...]
140who          ::= a | u | g | o
141op           ::= + | \- | =
142perm         ::= r | s | t | w | x | X | u | g | o
143.Ed
144.Pp
145The
146.Ar who
147symbols ``u'', ``g'', and ``o'' specify the user, group, and other parts
148of the mode bits, respectively.
149The
150.Ar who
151symbol ``a'' is equivalent to ``ugo''.
152.Pp
153.ne 1i
154The
155.Ar perm
156symbols represent the portions of the mode bits as follows:
157.Pp
158.Bl -tag -width Ds -compact -offset indent
159.It r
160The read bits.
161.It s
162The set-user-ID-on-execution and set-group-ID-on-execution bits.
163.It t
164The sticky bit.
165.It w
166The write bits.
167.It x
168The execute/search bits.
169.It X
170The execute/search bits if the file is a directory or any of the
171execute/search bits are set in the original (unmodified) mode.
172Operations with the
173.Ar perm
174symbol ``X'' are only meaningful in conjunction with the
175.Ar op
176symbol ``+'', and are ignored in all other cases.
177.It u
178The user permission bits in the mode of the original file.
179.It g
180The group permission bits in the mode of the original file.
181.It o
182The other permission bits in the mode of the original file.
183.El
184.Pp
185The
186.Ar op
187symbols represent the operation performed, as follows:
188.Bl -tag -width 4n
189.It +
190If no value is supplied for
191.Ar perm ,
192the ``+'' operation has no effect.
193If no value is supplied for
194.Ar who ,
195each permission bit specified in
196.Ar perm ,
197for which the corresponding bit in the file mode creation mask
198is clear, is set.
199Otherwise, the mode bits represented by the specified
200.Ar who
201and
202.Ar perm
203values are set.
204.It \&\-
205If no value is supplied for
206.Ar perm ,
207the ``\-'' operation has no effect.
208If no value is supplied for
209.Ar who ,
210each permission bit specified in
211.Ar perm ,
212for which the corresponding bit in the file mode creation mask
213is clear, is cleared.
214Otherwise, the mode bits represented by the specified
215.Ar who
216and
217.Ar perm
218values are cleared.
219.It =
220The mode bits specified by the
221.Ar who
222value are cleared, or, if no who value is specified, the owner, group
223and other mode bits are cleared.
224Then, if no value is supplied for
225.Ar who ,
226each permission bit specified in
227.Ar perm ,
228for which the corresponding bit in the file mode creation mask
229is clear, is set.
230Otherwise, the mode bits represented by the specified
231.Ar who
232and
233.Ar perm
234values are set.
235.El
236.Pp
237Each
238.Ar clause
239specifies one or more operations to be performed on the mode
240bits, and each operation is applied to the mode bits in the
241order specified.
242.Pp
243Operations upon the other permissions only (specified by the symbol
244``o'' by itself), in combination with the
245.Ar perm
246symbols ``s'' or ``t'', are ignored.
247.Sh EXAMPLES
248.Bl -tag -width "u=rwx,go=u-w" -compact
249.It Li 644
250make a file readable by anyone and writable by the owner only.
251.Pp
252.It Li go-w
253deny write permission to group and others.
254.Pp
255.It Li =rw,+X
256set the read and write permissions to the usual defaults, but
257retain any execute permissions that are currently set.
258.Pp
259.It Li +X
260make a directory or file searchable/executable by everyone if it is
261already searchable/executable by anyone.
262.Pp
263.It Li 755
264.It Li u=rwx,go=rx
265.It Li u=rwx,go=u-w
266make a file readable/executable by everyone and writable by the owner only.
267.Pp
268.It Li go=
269clear all mode bits for group and others.
270.Pp
271.It Li g=u-w
272set the group bits equal to the user bits, but clear the group write bit.
273.El
274.Sh BUGS
275There's no
276.Ar perm
277option for the naughty bits.
278.Sh SEE ALSO
279.Xr install 1 ,
280.Xr chmod 2 ,
281.Xr stat 2 ,
282.Xr umask 2 ,
283.Xr fts 3 ,
284.Xr setmode 3 ,
285.Xr symlink 7 ,
286.Xr chown 8
287.Sh STANDARDS
288The
289.Nm chmod
290utility is expected to be
291.St -p1003.2
292compatible with the exception of the
293.Ar perm
294symbols
295.Dq t
296and
297.Dq X
298which are not included in that standard.
299