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