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.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. All advertising materials mentioning features or use of this software 16.\" must display the following acknowledgement: 17.\" This product includes software developed by the University of 18.\" California, Berkeley and its contributors. 19.\" 4. Neither the name of the University nor the names of its contributors 20.\" may be used to endorse or promote products derived from this software 21.\" without specific prior written permission. 22.\" 23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33.\" SUCH DAMAGE. 34.\" 35.\" @(#)chmod.1 8.4 (Berkeley) 3/31/94 36.\" $FreeBSD$ 37.\" 38.Dd March 31, 1994 39.Dt CHMOD 1 40.Os 41.Sh NAME 42.Nm chmod 43.Nd change file modes 44.Sh SYNOPSIS 45.Nm chmod 46.Oo 47.Fl f 48.Fl R 49.Op Fl H | Fl L | Fl P 50.Fl v 51.Oc 52.Ar mode 53.Ar file ... 54.Sh DESCRIPTION 55The 56.Nm 57utility modifies the file mode bits of the listed files 58as specified by the 59.Ar mode 60operand. 61.Pp 62The options are as follows: 63.Bl -tag -width Ds 64.It Fl H 65If the 66.Fl R 67option is specified, symbolic links on the command line are followed. 68(Symbolic links encountered in the tree traversal are not followed.) 69.It Fl L 70If the 71.Fl R 72option is specified, all symbolic links are followed. 73.It Fl P 74If the 75.Fl R 76option is specified, no symbolic links are followed. 77.It Fl R 78Change the modes of the file hierarchies rooted in the files 79instead of just the files themselves. 80.It Fl f 81Do not display a diagnostic message if 82.Nm 83could not modify the mode for 84.It Fl v 85Cause 86.Nm 87to be verbose, showing files as the mode is modified. 88.Va file . 89.El 90.Pp 91Symbolic links do not have modes, so unless the 92.Fl H 93or 94.Fl L 95option is set, 96.Nm 97on a symbolic link always succeeds and has no effect. 98The 99.Fl H , 100.Fl L 101and 102.Fl P 103options are ignored unless the 104.Fl R 105option is specified. 106In addition, these options override each other and the 107command's actions are determined by the last one specified. 108.Pp 109Only the owner of a file or the super-user is permitted to change 110the mode of a file. 111.Sh DIAGNOSTICS 112The 113.Nm 114utility exits 0 on success, and >0 if an error occurs. 115.Sh MODES 116Modes may be absolute or symbolic. 117An absolute mode is an octal number constructed from the sum of 118one or more of the following values: 119.Pp 120.Bl -tag -width 6n -compact -offset indent 121.It Li 4000 122(the set-user-ID-on-execution bit) Executable files with this bit set 123will run with effective uid set to the uid of the file owner. 124Directories with the set-user-id bit set will force all files and 125sub-directories created in them to be owned by the directory owner 126and not by the uid of the creating process, if the underlying file 127system supports this feature: see 128.Xr chmod 2 129and the 130.Ar suiddir 131option to 132.Xr mount 8 . 133.It Li 2000 134(the set-group-ID-on-execution bit) Executable files with this bit set 135will run with effective gid set to the gid of the file owner. 136.It Li 1000 137(the sticky bit) 138When set on a directory, unprivileged users can delete and rename 139only those files in the directory that are owned by them, regardless of 140the permissions on the directory. Under FreeBSD, the sticky bit is 141ignored for executable files and may only be set for directories (see 142.Xr sticky 8 ). 143.It Li 0400 144Allow read by owner. 145.It Li 0200 146Allow write by owner. 147.It Li 0100 148For files, allow execution by owner. For directories, allow the owner to 149search in the directory. 150.It Li 0040 151Allow read by group members. 152.It Li 0020 153Allow write by group members. 154.It Li 0010 155For files, allow execution by group members. For directories, allow 156group members to search in the directory. 157.It Li 0004 158Allow read by others. 159.It Li 0002 160Allow write by others. 161.It Li 0001 162For files, allow execution by others. For directories allow others to 163search in the directory. 164.El 165.Pp 166For example, the absolute mode that permits read, write and execute by 167the owner, read and execute by group members, read and execute by 168others, and no set-uid or set-gid behaviour is 755 169(400+200+100+040+010+004+001). 170.Pp 171The symbolic mode is described by the following grammar: 172.Bd -literal -offset indent 173mode ::= clause [, clause ...] 174clause ::= [who ...] [action ...] last_action 175action ::= op [perm ...] 176last_action ::= op [perm ...] 177who ::= a | u | g | o 178op ::= + | \- | = 179perm ::= r | s | t | w | x | X | u | g | o 180.Ed 181.Pp 182The 183.Ar who 184symbols ``u'', ``g'', and ``o'' specify the user, group, and other parts 185of the mode bits, respectively. 186The 187.Ar who 188symbol ``a'' is equivalent to ``ugo''. 189.Pp 190.ne 1i 191The 192.Ar perm 193symbols represent the portions of the mode bits as follows: 194.Pp 195.Bl -tag -width Ds -compact -offset indent 196.It r 197The read bits. 198.It s 199The set-user-ID-on-execution and set-group-ID-on-execution bits. 200.It t 201The sticky bit. 202.It w 203The write bits. 204.It x 205The execute/search bits. 206.It X 207The execute/search bits if the file is a directory or any of the 208execute/search bits are set in the original (unmodified) mode. 209Operations with the 210.Ar perm 211symbol ``X'' are only meaningful in conjunction with the 212.Ar op 213symbol ``+'', and are ignored in all other cases. 214.It u 215The user permission bits in the mode of the original file. 216.It g 217The group permission bits in the mode of the original file. 218.It o 219The other permission bits in the mode of the original file. 220.El 221.Pp 222The 223.Ar op 224symbols represent the operation performed, as follows: 225.Bl -tag -width 4n 226.It + 227If no value is supplied for 228.Ar perm , 229the ``+'' operation has no effect. 230If no value is supplied for 231.Ar who , 232each permission bit specified in 233.Ar perm , 234for which the corresponding bit in the file mode creation mask 235is clear, is set. 236Otherwise, the mode bits represented by the specified 237.Ar who 238and 239.Ar perm 240values are set. 241.It \&\- 242If no value is supplied for 243.Ar perm , 244the ``\-'' operation has no effect. 245If no value is supplied for 246.Ar who , 247each permission bit specified in 248.Ar perm , 249for which the corresponding bit in the file mode creation mask 250is clear, is cleared. 251Otherwise, the mode bits represented by the specified 252.Ar who 253and 254.Ar perm 255values are cleared. 256.It = 257The mode bits specified by the 258.Ar who 259value are cleared, or, if no who value is specified, the owner, group 260and other mode bits are cleared. 261Then, if no value is supplied for 262.Ar who , 263each permission bit specified in 264.Ar perm , 265for which the corresponding bit in the file mode creation mask 266is clear, is set. 267Otherwise, the mode bits represented by the specified 268.Ar who 269and 270.Ar perm 271values are set. 272.El 273.Pp 274Each 275.Ar clause 276specifies one or more operations to be performed on the mode 277bits, and each operation is applied to the mode bits in the 278order specified. 279.Pp 280Operations upon the other permissions only (specified by the symbol 281``o'' by itself), in combination with the 282.Ar perm 283symbols ``s'' or ``t'', are ignored. 284.Sh EXAMPLES 285.Bl -tag -width "u=rwx,go=u-w" -compact 286.It Li 644 287make a file readable by anyone and writable by the owner only. 288.Pp 289.It Li go-w 290deny write permission to group and others. 291.Pp 292.It Li =rw,+X 293set the read and write permissions to the usual defaults, but 294retain any execute permissions that are currently set. 295.Pp 296.It Li +X 297make a directory or file searchable/executable by everyone if it is 298already searchable/executable by anyone. 299.Pp 300.It Li 755 301.It Li u=rwx,go=rx 302.It Li u=rwx,go=u-w 303make a file readable/executable by everyone and writable by the owner only. 304.Pp 305.It Li go= 306clear all mode bits for group and others. 307.Pp 308.It Li g=u-w 309set the group bits equal to the user bits, but clear the group write bit. 310.El 311.Sh BUGS 312There's no 313.Ar perm 314option for the naughty bits. 315.Sh COMPATIBILITY 316The 317.Fl v 318option is non-standard and its use in scripts is not recommended. 319.Sh SEE ALSO 320.Xr chflags 1 , 321.Xr install 1 , 322.Xr chmod 2 , 323.Xr stat 2 , 324.Xr umask 2 , 325.Xr fts 3 , 326.Xr setmode 3 , 327.Xr symlink 7 , 328.Xr chown 8 , 329.Xr mount 8 , 330.Xr sticky 8 331.Sh STANDARDS 332The 333.Nm 334utility is expected to be 335.St -p1003.2 336compatible with the exception of the 337.Ar perm 338symbols 339.Dq t 340and 341.Dq X 342which are not included in that standard. 343.Sh HISTORY 344A 345.Nm 346command appeared in 347.At v1 . 348