xref: /minix/bin/chmod/chmod.1 (revision 02efe53e)
1.\"	$NetBSD: chmod.1,v 1.26 2016/08/11 00:10:42 sevan 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 August 11, 2016
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.
109The default is as if the
110.Fl P
111option had been specified.
112.Pp
113Only the owner of a file or the super-user is permitted to change
114the mode of a file.
115.Sh EXIT STATUS
116The
117.Nm
118utility exits 0 on success, and \*[Gt]0 if an error occurs.
119.Sh MODES
120Modes may be absolute or symbolic.
121An absolute mode is an octal number constructed by
122.Em or Ap ing
123the following values:
124.Pp
125.Bl -tag -width 6n -compact -offset indent
126.It Li 4000
127set-user-ID-on-execution
128.It Li 2000
129set-group-ID-on-execution
130.It Li 1000
131sticky bit, see
132.Xr chmod 2
133.It Li 0400
134read by owner
135.It Li 0200
136write by owner
137.It Li 0100
138execute (or search for directories) by owner
139.It Li 0070
140read, write, execute/search by group
141.It Li 0007
142read, write, execute/search by others
143.El
144.Pp
145The read, write, and execute/search values for group and others
146are encoded as described for owner.
147.Pp
148The symbolic mode is described by the following grammar:
149.Bd -literal -offset indent
150mode         ::= clause [, clause ...]
151clause       ::= [who ...] [action ...] last_action
152action       ::= op [perm ...]
153last_action  ::= op [perm ...]
154who          ::= a | u | g | o
155op           ::= + | \- | =
156perm         ::= r | s | t | w | x | X | u | g | o
157.Ed
158.Pp
159The
160.Ar who
161symbols ``u'', ``g'', and ``o'' specify the user, group, and other parts
162of the mode bits, respectively.
163The
164.Ar who
165symbol ``a'' is equivalent to ``ugo''.
166.Pp
167The
168.Ar perm
169symbols represent the portions of the mode bits as follows:
170.Pp
171.Bl -tag -width Ds -compact -offset indent
172.It r
173The read bits.
174.It s
175The set-user-ID-on-execution and set-group-ID-on-execution bits.
176.It t
177The sticky bit.
178.It w
179The write bits.
180.It x
181The execute/search bits.
182.It X
183The execute/search bits if the file is a directory or any of the
184execute/search bits are set in the original (unmodified) mode.
185Operations with the
186.Ar perm
187symbol ``X'' are only meaningful in conjunction with the
188.Ar op
189symbol ``+'', and are ignored in all other cases.
190.It u
191The user permission bits in the mode of the original file.
192.It g
193The group permission bits in the mode of the original file.
194.It o
195The other permission bits in the mode of the original file.
196.El
197.Pp
198The
199.Ar op
200symbols represent the operation performed, as follows:
201.Bl -tag -width 4n
202.It +
203If no value is supplied for
204.Ar perm ,
205the ``+'' operation has no effect.
206If no value is supplied for
207.Ar who ,
208each permission bit specified in
209.Ar perm ,
210for which the corresponding bit in the file mode creation mask
211is clear, is set.
212Otherwise, the mode bits represented by the specified
213.Ar who
214and
215.Ar perm
216values are set.
217.It \&\-
218If no value is supplied for
219.Ar perm ,
220the ``\-'' operation has no effect.
221If 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 cleared.
227Otherwise, the mode bits represented by the specified
228.Ar who
229and
230.Ar perm
231values are cleared.
232.It =
233The mode bits specified by the
234.Ar who
235value are cleared, or, if no who value is specified, the owner, group
236and other mode bits are cleared.
237Then, if no value is supplied for
238.Ar who ,
239each permission bit specified in
240.Ar perm ,
241for which the corresponding bit in the file mode creation mask
242is clear, is set.
243Otherwise, the mode bits represented by the specified
244.Ar who
245and
246.Ar perm
247values are set.
248.El
249.Pp
250Each
251.Ar clause
252specifies one or more operations to be performed on the mode
253bits, and each operation is applied to the mode bits in the
254order specified.
255.Pp
256Operations upon the other permissions only (specified by the symbol
257``o'' by itself), in combination with the
258.Ar perm
259symbols ``s'' or ``t'', are ignored.
260.Sh EXAMPLES
261.Bl -tag -width "u=rwx,go=u-w" -compact
262.It Li 644
263make a file readable by anyone and writable by the owner only.
264.Pp
265.It Li go-w
266deny write permission to group and others.
267.Pp
268.It Li =rw,+X
269set the read and write permissions to the usual defaults, but
270retain any execute permissions that are currently set.
271.Pp
272.It Li +X
273make a directory or file searchable/executable by everyone if it is
274already searchable/executable by anyone.
275.Pp
276.It Li 755
277.It Li u=rwx,go=rx
278.It Li u=rwx,go=u-w
279make a file readable/executable by everyone and writable by the owner only.
280.Pp
281.It Li go=
282clear all mode bits for group and others.
283.Pp
284.It Li g=u-w
285set the group bits equal to the user bits, but clear the group write bit.
286.El
287.Sh SEE ALSO
288.Xr chflags 1 ,
289.Xr install 1 ,
290.Xr chmod 2 ,
291.Xr stat 2 ,
292.Xr umask 2 ,
293.Xr fts 3 ,
294.Xr setmode 3 ,
295.Xr symlink 7 ,
296.Xr chown 8
297.Sh STANDARDS
298The
299.Nm
300utility is expected to be
301.St -p1003.2-92
302compatible with the exception of the
303.Ar perm
304symbol
305.Dq t
306which is not included in that standard.
307.Sh HISTORY
308A
309.Nm
310utility appeared in
311.At v1 .
312.Sh BUGS
313There's no
314.Ar perm
315option for the naughty bits.
316