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