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 26, 2009 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. 67(Symbolic links encountered in the tree traversal are not followed by 68default.) 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. 84.It Fl v 85Cause 86.Nm 87to be verbose, showing filenames as the mode is modified. 88If the 89.Fl v 90flag is specified more than once, the old and new modes of the file 91will also be printed, in both octal and symbolic notation. 92.El 93.Pp 94The 95.Fl H , 96.Fl L 97and 98.Fl P 99options are ignored unless the 100.Fl R 101option is specified. 102In addition, these options override each other and the 103command's actions are determined by the last one specified. 104.Pp 105Only the owner of a file or the super-user is permitted to change 106the mode of a file. 107.Sh EXIT STATUS 108.Ex -std 109.Sh MODES 110Modes may be absolute or symbolic. 111An absolute mode is an octal number constructed from the sum of 112one or more of the following values: 113.Pp 114.Bl -tag -width 6n -compact -offset indent 115.It Li 4000 116(the setuid bit). 117Executable files with this bit set 118will run with effective uid set to the uid of the file owner. 119Directories with this bit set will force all files and 120sub-directories created in them to be owned by the directory owner 121and not by the uid of the creating process, if the underlying file 122system supports this feature: see 123.Xr chmod 2 124and the 125.Cm suiddir 126option to 127.Xr mount 8 . 128.It Li 2000 129(the setgid bit). 130Executable files with this bit set 131will run with effective gid set to the gid of the file owner. 132.It Li 1000 133(the sticky bit). 134See 135.Xr chmod 2 136and 137.Xr sticky 7 . 138.It Li 0400 139Allow read by owner. 140.It Li 0200 141Allow write by owner. 142.It Li 0100 143For files, allow execution by owner. 144For directories, allow the owner to 145search in the directory. 146.It Li 0040 147Allow read by group members. 148.It Li 0020 149Allow write by group members. 150.It Li 0010 151For files, allow execution by group members. 152For directories, allow 153group members to search in the directory. 154.It Li 0004 155Allow read by others. 156.It Li 0002 157Allow write by others. 158.It Li 0001 159For files, allow execution by others. 160For directories allow others to 161search in the directory. 162.El 163.Pp 164For example, the absolute mode that permits read, write and execute by 165the owner, read and execute by group members, read and execute by 166others, and no set-uid or set-gid behaviour is 755 167(400+200+100+040+010+004+001). 168.Pp 169The symbolic mode is described by the following grammar: 170.Bd -literal -offset indent 171mode ::= clause [, clause ...] 172clause ::= [who ...] [action ...] action 173action ::= op [perm ...] 174who ::= a | u | g | o 175op ::= + | \- | = 176perm ::= r | s | t | w | x | X | u | g | o 177.Ed 178.Pp 179The 180.Ar who 181symbols ``u'', ``g'', and ``o'' specify the user, group, and other parts 182of the mode bits, respectively. 183The 184.Ar who 185symbol ``a'' is equivalent to ``ugo''. 186.Pp 187The 188.Ar perm 189symbols represent the portions of the mode bits as follows: 190.Pp 191.Bl -tag -width Ds -compact -offset indent 192.It r 193The read bits. 194.It s 195The set-user-ID-on-execution and set-group-ID-on-execution bits. 196.It t 197The sticky bit. 198.It w 199The write bits. 200.It x 201The execute/search bits. 202.It X 203The execute/search bits if the file is a directory or any of the 204execute/search bits are set in the original (unmodified) mode. 205Operations with the 206.Ar perm 207symbol ``X'' are only meaningful in conjunction with the 208.Ar op 209symbol ``+'', and are ignored in all other cases. 210.It u 211The user permission bits in the original mode of the file. 212.It g 213The group permission bits in the original mode of the file. 214.It o 215The other permission bits in the original mode of the file. 216.El 217.Pp 218The 219.Ar op 220symbols represent the operation performed, as follows: 221.Bl -tag -width 4n 222.It + 223If no value is supplied for 224.Ar perm , 225the ``+'' operation has no effect. 226If no value is supplied for 227.Ar who , 228each permission bit specified in 229.Ar perm , 230for which the corresponding bit in the file mode creation mask 231(see 232.Xr umask 2 ) 233is clear, is set. 234Otherwise, the mode bits represented by the specified 235.Ar who 236and 237.Ar perm 238values are set. 239.It \&\- 240If no value is supplied for 241.Ar perm , 242the ``\-'' operation has no effect. 243If no value is supplied for 244.Ar who , 245each permission bit specified in 246.Ar perm , 247for which the corresponding bit in the file mode creation mask 248is clear, is cleared. 249Otherwise, the mode bits represented by the specified 250.Ar who 251and 252.Ar perm 253values are cleared. 254.It = 255The mode bits specified by the 256.Ar who 257value are cleared, or, if no 258.Ar who 259value 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.Pp 285The ``w'' permission on directories will permit file creation, relocation, 286and copy into that directory. 287Files created within the directory itself will inherit its group ID. 288.Sh EXAMPLES 289.Bl -tag -width "u=rwx,go=u-w" -compact 290.It Li 644 291make a file readable by anyone and writable by the owner only. 292.Pp 293.It Li go-w 294deny write permission to group and others. 295.Pp 296.It Li =rw,+X 297set the read and write permissions to the usual defaults, but 298retain any execute permissions that are currently set. 299.Pp 300.It Li +X 301make a directory or file searchable/executable by everyone if it is 302already searchable/executable by anyone. 303.Pp 304.It Li 755 305.It Li u=rwx,go=rx 306.It Li u=rwx,go=u-w 307make a file readable/executable by everyone and writable by the owner only. 308.Pp 309.It Li go= 310clear all mode bits for group and others. 311.Pp 312.It Li g=u-w 313set the group bits equal to the user bits, but clear the group write bit. 314.El 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 setfacl 1 , 323.Xr chmod 2 , 324.Xr stat 2 , 325.Xr umask 2 , 326.Xr fts 3 , 327.Xr setmode 3 , 328.Xr sticky 7 , 329.Xr symlink 7 , 330.Xr chown 8 , 331.Xr mount 8 332.Sh STANDARDS 333The 334.Nm 335utility is expected to be 336.St -p1003.2 337compatible with the exception of the 338.Ar perm 339symbol 340.Dq t 341which is not included in that standard. 342.Sh HISTORY 343A 344.Nm 345command appeared in 346.At v1 . 347.Sh BUGS 348There is no 349.Ar perm 350option for the naughty bits of a horse. 351