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