xref: /netbsd-src/bin/chmod/chmod.1 (revision 7f21db1c0118155e0dd40b75182e30c589d9f63e)
1.\"	$NetBSD: chmod.1,v 1.23 2010/01/22 05:41:36 snj 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 January 22, 2010
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 fh
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 f
77Do not display a diagnostic message or modify the exit status if
78.Nm
79fails to change the mode of a file.
80.It Fl h
81If
82.Ar file
83is symbolic link, the mode of the link is changed.
84.El
85.Pp
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.Sh EXIT STATUS
100The
101.Nm
102utility exits 0 on success, and \*[Gt]0 if an error occurs.
103.Sh MODES
104Modes may be absolute or symbolic.
105An absolute mode is an octal number constructed by
106.Em or Ap 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
116.Xr 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
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 SEE ALSO
272.Xr chflags 1 ,
273.Xr install 1 ,
274.Xr chmod 2 ,
275.Xr stat 2 ,
276.Xr umask 2 ,
277.Xr fts 3 ,
278.Xr setmode 3 ,
279.Xr symlink 7 ,
280.Xr chown 8
281.Sh STANDARDS
282The
283.Nm
284utility is expected to be
285.St -p1003.2-92
286compatible with the exception of the
287.Ar perm
288symbol
289.Dq t
290which is not included in that standard.
291.Sh BUGS
292There's no
293.Ar perm
294option for the naughty bits.
295