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