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