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