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