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