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