xref: /dragonfly/bin/chmod/chmod.1 (revision 73610d44)
1.\" Copyright (c) 1989, 1990, 1993, 1994
2.\"	The Regents of the University of California.  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. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\"	@(#)chmod.1	8.4 (Berkeley) 3/31/94
32.\" $FreeBSD: src/bin/chmod/chmod.1,v 1.17.2.16 2003/02/24 03:01:00 trhodes Exp $
33.\" $DragonFly: src/bin/chmod/chmod.1,v 1.3 2006/02/17 19:33:30 swildner Exp $
34.\"
35.Dd March 31, 1994
36.Dt CHMOD 1
37.Os
38.Sh NAME
39.Nm chmod
40.Nd change file modes
41.Sh SYNOPSIS
42.Nm
43.Op Fl fhv
44.Op Fl R Op Fl H | L | P
45.Ar mode
46.Ar
47.Sh DESCRIPTION
48The
49.Nm
50utility modifies the file mode bits of the listed files
51as specified by the
52.Ar mode
53operand.
54.Pp
55The options are as follows:
56.Bl -tag -width indent
57.It Fl f
58Do not display a diagnostic message if
59.Nm
60could not modify the mode for
61.Va file ,
62nor modify the exit status to reflect such failures.
63.It Fl H
64If the
65.Fl R
66option is specified, symbolic links on the command line are followed.
67(Symbolic links encountered in the tree traversal are not followed by
68default.)
69.It Fl h
70If the file is a symbolic link, change the mode of the link itself
71rather than the file that the link points to.
72.It Fl L
73If the
74.Fl R
75option is specified, all symbolic links are followed.
76.It Fl P
77If the
78.Fl R
79option is specified, no symbolic links are followed.
80This is the default.
81.It Fl R
82Change the modes of the file hierarchies rooted in the files
83instead of just the files themselves.
84.It Fl v
85Cause
86.Nm
87to be verbose, showing filenames as the mode is modified.
88.El
89.Pp
90The
91.Fl H ,
92.Fl L
93and
94.Fl P
95options are ignored unless the
96.Fl R
97option is specified.
98In addition, these options override each other and the
99command's actions are determined by the last one specified.
100.Pp
101Only the owner of a file or the super-user is permitted to change
102the mode of a file.
103.Sh EXIT STATUS
104.Ex -std
105.Sh EXAMPLES
106.Bl -tag -width "u=rwx,go=u-w" -compact
107.It Li 644
108make a file readable by anyone and writable by the owner only.
109.Pp
110.It Li go-w
111deny write permission to group and others.
112.Pp
113.It Li =rw,+X
114set the read and write permissions to the usual defaults, but
115retain any execute permissions that are currently set.
116.Pp
117.It Li +X
118make a directory or file searchable/executable by everyone if it is
119already searchable/executable by anyone.
120.Pp
121.It Li 755
122.It Li u=rwx,go=rx
123.It Li u=rwx,go=u-w
124make a file readable/executable by everyone and writable by the owner only.
125.Pp
126.It Li go=
127clear all mode bits for group and others.
128.Pp
129.It Li g=u-w
130set the group bits equal to the user bits, but clear the group write bit.
131.El
132.Sh MODES
133Modes may be absolute or symbolic.
134An absolute mode is an octal number constructed from the sum of
135one or more of the following values:
136.Pp
137.Bl -tag -width 6n -compact -offset indent
138.It Li 4000
139(the setuid bit).
140Executable files with this bit set
141will run with effective uid set to the uid of the file owner.
142Directories with this bit set will force all files and
143sub-directories created in them to be owned by the directory owner
144and not by the uid of the creating process, if the underlying file
145system supports this feature: see
146.Xr chmod 2
147and the
148.Cm suiddir
149option to
150.Xr mount 8 .
151.It Li 2000
152(the setgid bit).
153Executable files with this bit set
154will run with effective gid set to the gid of the file owner.
155.It Li 1000
156(the sticky bit).
157See
158.Xr chmod 2
159and
160.Xr sticky 8 .
161.It Li 0400
162Allow read by owner.
163.It Li 0200
164Allow write by owner.
165.It Li 0100
166For files, allow execution by owner.
167For directories, allow the owner to
168search in the directory.
169.It Li 0040
170Allow read by group members.
171.It Li 0020
172Allow write by group members.
173.It Li 0010
174For files, allow execution by group members.
175For directories, allow
176group members to search in the directory.
177.It Li 0004
178Allow read by others.
179.It Li 0002
180Allow write by others.
181.It Li 0001
182For files, allow execution by others.
183For directories allow others to
184search in the directory.
185.El
186.Pp
187For example, the absolute mode that permits read, write and execute by
188the owner, read and execute by group members, read and execute by
189others, and no set-uid or set-gid behaviour is 755
190(400+200+100+040+010+004+001).
191.Pp
192The symbolic mode is described by the following grammar:
193.Bd -literal -offset indent
194mode         ::= clause [, clause ...]
195clause       ::= [who ...] [action ...] action
196action       ::= op [perm ...]
197who          ::= a | u | g | o
198op           ::= + | \- | =
199perm         ::= r | s | t | w | x | X | u | g | o
200.Ed
201.Pp
202The
203.Ar who
204symbols ``u'', ``g'', and ``o'' specify the user, group, and other parts
205of the mode bits, respectively.
206The
207.Ar who
208symbol ``a'' is equivalent to ``ugo''.
209.Pp
210The
211.Ar perm
212symbols represent the portions of the mode bits as follows:
213.Pp
214.Bl -tag -width Ds -compact -offset indent
215.It r
216The read bits.
217.It s
218The set-user-ID-on-execution and set-group-ID-on-execution bits.
219.It t
220The sticky bit.
221.It w
222The write bits.
223.It x
224The execute/search bits.
225.It X
226The execute/search bits if the file is a directory or any of the
227execute/search bits are set in the original (unmodified) mode.
228Operations with the
229.Ar perm
230symbol ``X'' are only meaningful in conjunction with the
231.Ar op
232symbol ``+'', and are ignored in all other cases.
233.It u
234The user permission bits in the original mode of the file.
235.It g
236The group permission bits in the original mode of the file.
237.It o
238The other permission bits in the original mode of the file.
239.El
240.Pp
241The
242.Ar op
243symbols represent the operation performed, as follows:
244.Bl -tag -width 4n
245.It +
246If no value is supplied for
247.Ar perm ,
248the ``+'' operation has no effect.
249If no value is supplied for
250.Ar who ,
251each permission bit specified in
252.Ar perm ,
253for which the corresponding bit in the file mode creation mask
254is clear, is set.
255Otherwise, the mode bits represented by the specified
256.Ar who
257and
258.Ar perm
259values are set.
260.It \&\-
261If no value is supplied for
262.Ar perm ,
263the ``\-'' operation has no effect.
264If no value is supplied for
265.Ar who ,
266each permission bit specified in
267.Ar perm ,
268for which the corresponding bit in the file mode creation mask
269is clear, is cleared.
270Otherwise, the mode bits represented by the specified
271.Ar who
272and
273.Ar perm
274values are cleared.
275.It =
276The mode bits specified by the
277.Ar who
278value are cleared, or, if no who value is specified, the owner, group
279and other mode bits are cleared.
280Then, if no value is supplied for
281.Ar who ,
282each permission bit specified in
283.Ar perm ,
284for which the corresponding bit in the file mode creation mask
285is clear, is set.
286Otherwise, the mode bits represented by the specified
287.Ar who
288and
289.Ar perm
290values are set.
291.El
292.Pp
293Each
294.Ar clause
295specifies one or more operations to be performed on the mode
296bits, and each operation is applied to the mode bits in the
297order specified.
298.Pp
299Operations upon the other permissions only (specified by the symbol
300``o'' by itself), in combination with the
301.Ar perm
302symbols ``s'' or ``t'', are ignored.
303.Sh COMPATIBILITY
304The
305.Fl v
306option is non-standard and its use in scripts is not recommended.
307.Sh SEE ALSO
308.Xr chflags 1 ,
309.Xr install 1 ,
310.Xr chmod 2 ,
311.Xr stat 2 ,
312.Xr umask 2 ,
313.Xr fts 3 ,
314.Xr setmode 3 ,
315.Xr symlink 7 ,
316.Xr chown 8 ,
317.Xr mount 8 ,
318.Xr sticky 8
319.Sh STANDARDS
320The
321.Nm
322utility is expected to be
323.St -p1003.2
324compatible with the exception of the
325.Ar perm
326symbol
327.Dq t
328which is not included in that standard.
329.Sh HISTORY
330A
331.Nm
332command appeared in
333.At v1 .
334.Sh BUGS
335There's no
336.Ar perm
337option for the naughty bits.
338