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