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