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