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.\" 4. 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.\" $FreeBSD$ 34.\" 35.Dd January 7, 2017 36.Dt CHMOD 1 37.Os 38.Sh NAME 39.Nm chmod 40.Nd change file modes 41.Sh SYNOPSIS 42.Nm 43.Op Fl fhv 44.Op Fl R Op Fl H | L | P 45.Ar mode 46.Ar 47.Sh DESCRIPTION 48The 49.Nm 50utility modifies the file mode bits of the listed files 51as specified by the 52.Ar mode 53operand. 54.Pp 55The options are as follows: 56.Bl -tag -width indent 57.It Fl f 58Do not display a diagnostic message if 59.Nm 60could not modify the mode for 61.Va file , 62nor modify the exit status to reflect such failures. 63.It Fl H 64If the 65.Fl R 66option is specified, symbolic links on the command line are followed 67and hence unaffected by the command. 68(Symbolic links encountered during tree traversal are not followed.) 69.It Fl h 70If the file is a symbolic link, change the mode of the link itself 71rather than the file that the link points to. 72.It Fl L 73If the 74.Fl R 75option is specified, all symbolic links are followed. 76.It Fl P 77If the 78.Fl R 79option is specified, no symbolic links are followed. 80This is the default. 81.It Fl R 82Change the modes of the file hierarchies rooted in the files, 83instead of just the files themselves. 84Beware of unintentionally matching the 85.Dq Pa ".." 86hard link to the parent directory when using wildcards like 87.Dq Li ".*" . 88.It Fl v 89Cause 90.Nm 91to be verbose, showing filenames as the mode is modified. 92If the 93.Fl v 94flag is specified more than once, the old and new modes of the file 95will also be printed, in both octal and symbolic notation. 96.El 97.Pp 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 109If 110.Nm 111receives a 112.Dv SIGINFO 113signal (see the 114.Cm status 115argument for 116.Xr stty 1 ) , 117then the current filename as well as the old and new modes are displayed. 118.Pp 119Only the owner of a file or the super-user is permitted to change 120the mode of a file. 121.Sh EXIT STATUS 122.Ex -std 123.Sh MODES 124Modes may be absolute or symbolic. 125An absolute mode is an octal number constructed from the sum of 126one or more of the following values: 127.Pp 128.Bl -tag -width 6n -compact -offset indent 129.It Li 4000 130(the setuid bit). 131Executable files with this bit set 132will run with effective uid set to the uid of the file owner. 133Directories with this bit set will force all files and 134sub-directories created in them to be owned by the directory owner 135and not by the uid of the creating process, if the underlying file 136system supports this feature: see 137.Xr chmod 2 138and the 139.Cm suiddir 140option to 141.Xr mount 8 . 142.It Li 2000 143(the setgid bit). 144Executable files with this bit set 145will run with effective gid set to the gid of the file owner. 146.It Li 1000 147(the sticky bit). 148See 149.Xr chmod 2 150and 151.Xr sticky 7 . 152.It Li 0400 153Allow read by owner. 154.It Li 0200 155Allow write by owner. 156.It Li 0100 157For files, allow execution by owner. 158For directories, allow the owner to 159search in the directory. 160.It Li 0040 161Allow read by group members. 162.It Li 0020 163Allow write by group members. 164.It Li 0010 165For files, allow execution by group members. 166For directories, allow 167group members to search in the directory. 168.It Li 0004 169Allow read by others. 170.It Li 0002 171Allow write by others. 172.It Li 0001 173For files, allow execution by others. 174For directories allow others to 175search in the directory. 176.El 177.Pp 178For example, the absolute mode that permits read, write and execute by 179the owner, read and execute by group members, read and execute by 180others, and no set-uid or set-gid behaviour is 755 181(400+200+100+040+010+004+001). 182.Pp 183The symbolic mode is described by the following grammar: 184.Bd -literal -offset indent 185mode ::= clause [, clause ...] 186clause ::= [who ...] [action ...] action 187action ::= op [perm ...] 188who ::= a | u | g | o 189op ::= + | \- | = 190perm ::= r | s | t | w | x | X | u | g | o 191.Ed 192.Pp 193The 194.Ar who 195symbols ``u'', ``g'', and ``o'' specify the user, group, and other parts 196of the mode bits, respectively. 197The 198.Ar who 199symbol ``a'' is equivalent to ``ugo''. 200.Pp 201The 202.Ar perm 203symbols represent the portions of the mode bits as follows: 204.Pp 205.Bl -tag -width Ds -compact -offset indent 206.It r 207The read bits. 208.It s 209The set-user-ID-on-execution and set-group-ID-on-execution bits. 210.It t 211The sticky bit. 212.It w 213The write bits. 214.It x 215The execute/search bits. 216.It X 217The execute/search bits if the file is a directory or any of the 218execute/search bits are set in the original (unmodified) mode. 219Operations with the 220.Ar perm 221symbol ``X'' are only meaningful in conjunction with the 222.Ar op 223symbol ``+'', and are ignored in all other cases. 224.It u 225The user permission bits in the original mode of the file. 226.It g 227The group permission bits in the original mode of the file. 228.It o 229The other permission bits in the original mode of the file. 230.El 231.Pp 232The 233.Ar op 234symbols represent the operation performed, as follows: 235.Bl -tag -width 4n 236.It + 237If no value is supplied for 238.Ar perm , 239the ``+'' operation has no effect. 240If no value is supplied for 241.Ar who , 242each permission bit specified in 243.Ar perm , 244for which the corresponding bit in the file mode creation mask 245(see 246.Xr umask 2 ) 247is clear, is set. 248Otherwise, the mode bits represented by the specified 249.Ar who 250and 251.Ar perm 252values are set. 253.It \&\- 254If no value is supplied for 255.Ar perm , 256the ``\-'' operation has no effect. 257If no value is supplied for 258.Ar who , 259each permission bit specified in 260.Ar perm , 261for which the corresponding bit in the file mode creation mask 262is clear, is cleared. 263Otherwise, the mode bits represented by the specified 264.Ar who 265and 266.Ar perm 267values are cleared. 268.It = 269The mode bits specified by the 270.Ar who 271value are cleared, or, if no 272.Ar who 273value is specified, the owner, group 274and other mode bits are cleared. 275Then, if no value is supplied for 276.Ar who , 277each permission bit specified in 278.Ar perm , 279for which the corresponding bit in the file mode creation mask 280is clear, is set. 281Otherwise, the mode bits represented by the specified 282.Ar who 283and 284.Ar perm 285values are set. 286.El 287.Pp 288Each 289.Ar clause 290specifies one or more operations to be performed on the mode 291bits, and each operation is applied to the mode bits in the 292order specified. 293.Pp 294Operations upon the other permissions only (specified by the symbol 295``o'' by itself), in combination with the 296.Ar perm 297symbols ``s'' or ``t'', are ignored. 298.Pp 299The ``w'' permission on directories will permit file creation, relocation, 300and copy into that directory. 301Files created within the directory itself will inherit its group ID. 302.Sh EXAMPLES 303.Bl -tag -width "u=rwx,go=u-w" -compact 304.It Li 644 305make a file readable by anyone and writable by the owner only. 306.Pp 307.It Li go-w 308deny write permission to group and others. 309.Pp 310.It Li =rw,+X 311set the read and write permissions to the usual defaults, but 312retain any execute permissions that are currently set. 313.Pp 314.It Li +X 315make a directory or file searchable/executable by everyone if it is 316already searchable/executable by anyone. 317.Pp 318.It Li 755 319.It Li u=rwx,go=rx 320.It Li u=rwx,go=u-w 321make a file readable/executable by everyone and writable by the owner only. 322.Pp 323.It Li go= 324clear all mode bits for group and others. 325.Pp 326.It Li g=u-w 327set the group bits equal to the user bits, but clear the group write bit. 328.El 329.Sh COMPATIBILITY 330The 331.Fl v 332option is non-standard and its use in scripts is not recommended. 333.Sh SEE ALSO 334.Xr chflags 1 , 335.Xr install 1 , 336.Xr setfacl 1 , 337.Xr chmod 2 , 338.Xr stat 2 , 339.Xr umask 2 , 340.Xr fts 3 , 341.Xr setmode 3 , 342.Xr sticky 7 , 343.Xr symlink 7 , 344.Xr chown 8 , 345.Xr mount 8 346.Sh STANDARDS 347The 348.Nm 349utility is expected to be 350.St -p1003.2 351compatible with the exception of the 352.Ar perm 353symbol 354.Dq t 355which is not included in that standard. 356.Sh HISTORY 357A 358.Nm 359command appeared in 360.At v1 . 361.Sh BUGS 362There is no 363.Ar perm 364option for the naughty bits of a horse. 365