xref: /original-bsd/bin/chmod/chmod.1 (revision babae2df)
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.\" %sccs.include.redist.roff%
8.\"
9.\"	@(#)chmod.1	8.2 (Berkeley) 03/25/94
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 | u | g | o
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.It u
131The user permission bits in the mode of the original file.
132.It g
133The group permission bits in the mode of the original file.
134.It o
135The other permission bits in the mode of the original file.
136.El
137.Pp
138The
139.Ar op
140symbols represent the operation performed, as follows:
141.Bl -tag -width 4n
142.It +
143If no value is supplied for
144.Ar perm ,
145the ``+'' operation has no effect.
146If no value is supplied for
147.Ar who ,
148each permission bit specified in
149.Ar perm ,
150for which the corresponding bit in the file mode creation mask
151is clear, is set.
152Otherwise, the mode bits represented by the specified
153.Ar who
154and
155.Ar perm
156values are set.
157.It \&\-
158If no value is supplied for
159.Ar perm ,
160the ``\-'' operation has no effect.
161If no value is supplied for
162.Ar who ,
163each permission bit specified in
164.Ar perm ,
165for which the corresponding bit in the file mode creation mask
166is clear, is cleared.
167Otherwise, the mode bits represented by the specified
168.Ar who
169and
170.Ar perm
171values are cleared.
172.It =
173The mode bits specified by the
174.Ar who
175value are cleared, or, if no who value is specified, the owner, group
176and other mode bits are cleared.
177Then, if no value is supplied for
178.Ar who ,
179each permission bit specified in
180.Ar perm ,
181for which the corresponding bit in the file mode creation mask
182is clear, is set.
183Otherwise, the mode bits represented by the specified
184.Ar who
185and
186.Ar perm
187values are set.
188.El
189.Pp
190Each
191.Ar clause
192specifies one or more operations to be performed on the mode
193bits, and each operation is applied to the mode bits in the
194order specified.
195.Pp
196Operations upon the other permissions only (specified by the symbol
197``o'' by itself), in combination with the
198.Ar perm
199symbols ``s'' or ``t'', are ignored.
200.Sh EXAMPLES
201.Bl -tag -width "u=rwx,go=u-w" -compact
202.It Li 644
203make a file readable by anyone and writable by the owner only.
204.Pp
205.It Li go-w
206deny write permission to group and others.
207.Pp
208.It Li =rw,+X
209set the read and write permissions to the usual defaults, but
210retain any execute permissions that are currently set.
211.Pp
212.It Li +X
213make a directory or file searchable/executable by everyone if it is
214already searchable/executable by anyone.
215.Pp
216.It Li 755
217.It Li u=rwx,go=rx
218.It Li u=rwx,go=u-w
219make a file readable/executable by everyone and writeable by the owner only.
220.Pp
221.It Li go=
222clear all mode bits for group and others.
223.Pp
224.It Li g=u-w
225set the group bits equal to the user bits, but clear the group write bit.
226.El
227.Sh BUGS
228There's no
229.Ar perm
230option for the naughty bits.
231.Sh SEE ALSO
232.Xr install 1 ,
233.Xr chmod 2 ,
234.Xr stat 2 ,
235.Xr umask 2 ,
236.Xr fts 3 ,
237.Xr setmode 3 ,
238.Xr symlink 7 ,
239.Xr chown 8
240.Sh STANDARDS
241The
242.Nm chmod
243utility is expected to be POSIX 1003.2
244compatible with the exception of the
245.Ar perm
246symbols
247.Dq t
248and
249.Dq X
250which are not included in that standard.
251