xref: /original-bsd/bin/chmod/chmod.1 (revision 3705696b)
1.\" Copyright (c) 1989, 1990, 1993
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.\" %sccs.include.redist.roff%
8.\"
9.\"	@(#)chmod.1	8.1 (Berkeley) 06/29/93
10.\"
11.Dd
12.Dt CHMOD 1
13.Os
14.Sh NAME
15.Nm chmod
16.Nd change file modes
17.Sh SYNOPSIS
18.Nm chmod
19.Op Fl HRh
20.Ar mode
21.Ar file ...
22.Sh DESCRIPTION
23The
24.Nm chmod
25utility modifies the file mode bits of the listed files
26as specified by the
27.Ar mode
28operand.
29.Pp
30The options are as follows:
31.Bl -tag -width Ds
32.It Fl H
33When encountering a symbolic link on the command line, follow it.  All other
34symbolic links encountered in the traversal are not followed.
35.It Fl R
36Traverse a file hierarchy.
37For each file that is of type directory,
38.Nm chmod
39changes the mode of all files in the file hierarchy below it followed
40by the mode of the directory itself.
41.It Fl h
42When encountering a symbolic link anywhere in the traversal, follow it.
43.El
44.Pp
45The mode of a symbolic link is immutable, so unless the
46.Fl h
47or
48.Fl H
49flag is set,
50.Nm chmod
51on a symbolic link is a no-op.
52.Pp
53Only the owner of a file or the super-user is permitted to change
54the mode of a file.
55.Pp
56The
57.Nm chmod
58utility exits 0 on success, and >0 if an error occurs.
59.Sh MODES
60Modes may be absolute or symbolic.
61An absolute mode is an octal number constructed by
62.Ar or-ing
63the following values:
64.Pp
65.Bl -tag -width 6n -compact -offset indent
66.It Li 4000
67set-user-ID-on-execution
68.It Li 2000
69set-group-ID-on-execution
70.It Li 1000
71sticky bit, see chmod(2)
72.It Li 0400
73read by owner
74.It Li 0200
75write by owner
76.It Li 0100
77execute (or search for directories) by owner
78.It Li 0070
79read, write, execute/search by group
80.It Li 0007
81read, write, execute/search by others
82.El
83.Pp
84The read, write, and execute/search values for group and others
85are encoded as described for owner.
86.Pp
87The symbolic mode is described by the following grammar:
88.Bd -literal -offset indent
89mode         ::= clause [, clause ...]
90clause       ::= [who ...] [action ...] last_action
91action       ::= op [perm ...]
92last_action  ::= op [perm ...]
93who          ::= a | u | g | o
94op           ::= + | \- | =
95perm         ::= r | s | t | w | x | X
96.Ed
97.Pp
98The
99.Ar who
100symbols ``u'', ``g'', and ``o'' specify the user, group, and other parts
101of the mode bits, respectively.
102The
103.Ar who
104symbol ``a'' is equivalent to ``ugo''.
105.Pp
106.ne 1i
107The
108.Ar perm
109symbols represent the portions of the mode bits as follows:
110.Pp
111.Bl -tag -width Ds -compact -offset indent
112.It r
113The read bits.
114.It s
115The set-user-ID-on-execution and set-group-ID-on-execution bits.
116.It t
117The sticky bit.
118.It w
119The write bits.
120.It x
121The execute/search bits.
122.It X
123The execute/search bits if the file is a directory or any of the
124execute/search bits are set in the original (unmodified) mode.
125Operations with the
126.Ar perm
127symbol ``X'' are only meaningful in conjunction with the
128.Ar op
129symbol ``+'', and are ignored in all other cases.
130.El
131.Pp
132The
133.Ar op
134symbols represent the operation performed, as follows:
135.Bl -tag -width 4n
136.It +
137If no value is supplied for
138.Ar perm ,
139the ``+'' operation has no effect.
140If no value is supplied for
141.Ar who ,
142each permission bit specified in
143.Ar perm ,
144for which the corresponding bit in the file mode creation mask
145is clear, is set.
146Otherwise, the mode bits represented by the specified
147.Ar who
148and
149.Ar perm
150values are set.
151.It \&\-
152If no value is supplied for
153.Ar perm ,
154the ``\-'' operation has no effect.
155If no value is supplied for
156.Ar who ,
157the mode bits represented by
158.Ar perm
159are cleared for the owner, group and other permissions.
160Otherwise, the mode bits represented by the specified
161.Ar who
162and
163.Ar perm
164values are cleared.
165.It =
166The mode bits specified by the
167.Ar who
168value are cleared, or, if no who value is specified, the owner, group
169and other mode bits are cleared.
170Then, if no value is supplied for
171.Ar who ,
172each permission bit specified in
173.Ar perm ,
174for which the corresponding bit in the file mode creation mask
175is clear, is set.
176Otherwise, the mode bits represented by the specified
177.Ar who
178and
179.Ar perm
180values are set.
181.El
182.Pp
183Each
184.Ar clause
185specifies one or more operations to be performed on the mode
186bits, and each operation is applied to the mode bits in the
187order specified.
188.Pp
189Operations upon the other permissions only (specified by the symbol
190``o'' by itself), in combination with the
191.Ar perm
192symbols ``s'' or ``t'', are ignored.
193.Sh EXAMPLES
194.Bl -tag -width "u=rwx,go=u-w" -compact
195.It Li 644
196make a file readable by anyone and writable by the owner only.
197.Pp
198.It Li go-w
199deny write permission to group and others.
200.Pp
201.It Li =rw,+X
202set the read and write permissions to the usual defaults, but
203retain any execute permissions that are currently set.
204.Pp
205.It Li +X
206make a directory or file searchable/executable by everyone if it is
207already searchable/executable by anyone.
208.Pp
209.It Li 755
210.It Li u=rwx,go=rx
211.It Li u=rwx,go=u-w
212make a file readable/executable by everyone and writeable by the owner only.
213.Pp
214.It Li go=
215clear all mode bits for group and others.
216.Pp
217.It Li g=u-w
218set the group bits equal to the user bits, but clear the group write bit.
219.El
220.Sh BUGS
221There's no
222.Ar perm
223option for the naughty bits.
224.Sh SEE ALSO
225.Xr install 1 ,
226.Xr chmod 2 ,
227.Xr stat 2 ,
228.Xr umask 2 ,
229.Xr fts 3 ,
230.Xr setmode 3 ,
231.Xr symlink 7 ,
232.Xr chown 8
233.Sh STANDARDS
234The
235.Nm chmod
236utility is expected to be POSIX 1003.2
237compatible with the exception of the
238.Ar perm
239symbols
240.Dq t
241and
242.Dq X
243which are not included in that standard.
244