xref: /386bsd/usr/src/bin/chmod/chmod.1 (revision a2142627)
1.\" Copyright (c) 1989, 1990 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" the Institute of Electrical and Electronics Engineers, Inc.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. All advertising materials mentioning features or use of this software
16.\"    must display the following acknowledgement:
17.\"	This product includes software developed by the University of
18.\"	California, Berkeley and its contributors.
19.\" 4. Neither the name of the University nor the names of its contributors
20.\"    may be used to endorse or promote products derived from this software
21.\"    without specific prior written permission.
22.\"
23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33.\" SUCH DAMAGE.
34.\"
35.\"	@(#)chmod.1	6.15 (Berkeley) 7/23/91
36.\"
37.Dd July 23, 1991
38.Dt CHMOD 1
39.Os
40.Sh NAME
41.Nm chmod
42.Nd change file modes
43.Sh SYNOPSIS
44.Nm chmod
45.Op Fl R
46.Ar mode
47.Ar file ...
48.Sh DESCRIPTION
49The
50.Nm chmod
51utility modifies the file mode bits of the listed files
52as specified by the
53.Ar mode
54operand.
55.Pp
56The options are as follows:
57.Bl -tag -width Ds
58.It Fl R
59Traverse a file hierarchy.
60For each file that is of type directory,
61.Nm chmod
62changes the mode of all files in the file hierarchy below it followed
63by the mode of the directory itself.
64.El
65.Pp
66Symbolic links are not indirected through, nor are their modes altered.
67.Pp
68Only the owner of a file or the super-user is permitted to change
69the mode of a file.
70.Pp
71The
72.Nm chmod
73utility exits 0 on success, and >0 if an error occurs.
74.Sh MODES
75Modes may be absolute or symbolic.
76An absolute mode is an octal number constructed by
77.Ar or Ap ing
78the following values:
79.Pp
80.Bl -tag -width 6n -compact -offset indent
81.It Li 4000
82set-user-ID-on-execution
83.It Li 2000
84set-group-ID-on-execution
85.It Li 1000
86sticky bit, see chmod(2)
87.It Li 0400
88read by owner
89.It Li 0200
90write by owner
91.It Li 0100
92execute (or search for directories) by owner
93.It Li 0070
94read, write, execute/search by group
95.It Li 0007
96read, write, execute/search by others
97.El
98.Pp
99The read, write, and execute/search values for group and others
100are encoded as described for owner.
101.Pp
102The symbolic mode is described by the following grammar:
103.Bd -literal -offset indent
104mode         ::= clause [, clause ...]
105clause       ::= [who ...] [action ...] last_action
106action       ::= op [perm ...]
107last_action  ::= op [perm ...]
108who          ::= a | u | g | o
109op           ::= + | \- | =
110perm         ::= r | s | t | w | X | x | u | g | o
111.Ed
112.Pp
113The
114.Ar who
115symbols ``u'', ``g'', and ``o'' specify the user, group, and other parts
116of the mode bits, respectively.
117The
118.Ar who
119symbol ``a'' is equivalent to ``ugo''.
120.Pp
121The
122.Ar perm
123symbols represent the portions of the mode bits as follows:
124.Pp
125.Bl -tag -width Ds -compact -offset indent
126.It r
127The read bits.
128.It s
129The set-user-ID-on-execution and set-group-ID-on-execution bits.
130.It t
131The sticky bit.
132.It w
133The write bits.
134.It x
135The execute/search bits.
136.It X
137The execute/search bits if the file is a directory or any of the
138execute/search bits are set in the original (unmodified) mode.
139Operations with the
140.Ar perm
141symbol ``X'' are only meaningful in conjunction with the
142.Ar op
143symbol ``+'', and it is ignored in all other cases.
144.El
145.Pp
146The
147.Ar op
148symbols represent the operation performed, as follows:
149.Bl -tag -width 4n
150.It +
151If no value is supplied for
152.Ar perm ,
153the ``+'' operation has no effect.
154If no value is supplied for
155.Ar who ,
156each permission bit specified in
157.Ar perm ,
158for which the corresponding bit in the file mode creation mask
159is clear, is set.
160Otherwise, the mode bits represented by the specified
161.Ar who
162and
163.Ar perm
164values are set.
165.It \&\-
166If no value is supplied for
167.Ar perm ,
168the ``\-'' operation has no effect.
169If no value is supplied for
170.Ar who ,
171the mode bits represented by
172.Ar perm
173are cleared for the owner, group and other permissions.
174Otherwise, the mode bits represented by the specified
175.Ar who
176and
177.Ar perm
178values are cleared.
179.It =
180The mode bits specified by the
181.Ar who
182value are cleared, or, if no who value is specified, the owner, group
183and other mode bits are cleared.
184Then, if no value is supplied for
185.Ar who ,
186each permission bit specified in
187.Ar perm ,
188for which the corresponding bit in the file mode creation mask
189is clear, is set.
190Otherwise, the mode bits represented by the specified
191.Ar who
192and
193.Ar perm
194values are set.
195.El
196.Pp
197Each
198.Ar clause
199specifies one or more operations to be performed on the mode
200bits, and each operation is applied to the mode bits in the
201order specified.
202.Pp
203Operations upon the other permissions only (specified by the symbol
204``o'' by itself), in combination with the
205.Ar perm
206symbols ``s'' or ``t'', are ignored.
207.Sh EXAMPLES
208.Bl -tag -width "u=rwx,go=u-w" -compact
209.It Li 644
210make a file readable by anyone and writable by the owner only.
211.Pp
212.It Li go-w
213deny write permission to group and others.
214.Pp
215.It Li =rw,+X
216set the read and write permissions to the usual defaults, but
217retain any execute permissions that are currently set.
218.Pp
219.It Li +X
220make a directory or file searchable/executable by everyone if it is
221already searchable/executable by anyone.
222.Pp
223.It Li 755
224.It Li u=rwx,go=rx
225.It Li u=rwx,go=u-w
226make a file readable/executable by everyone and writeable by the owner only.
227.Pp
228.It Li go=
229clear all mode bits for group and others.
230.Pp
231.It Li g=u-w
232set the group bits equal to the user bits, but clear the group write bit.
233.El
234.Sh BUGS
235There's no
236.Ar perm
237option for the naughty bits.
238.Sh SEE ALSO
239.Xr install 1 ,
240.Xr chmod 2 ,
241.Xr stat 2 ,
242.Xr umask 2 ,
243.Xr fts 3 ,
244.Xr setmode 3 ,
245.Xr chown 8
246.Sh STANDARDS
247The
248.Nm chmod
249utility is expected to be
250.St -p1003.2
251compatible with the exception
252of the
253.Ar perm
254symbols
255.Dq t
256and
257.Dq X
258which are not included in that standard.
259