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 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 by 69default.) 70.It Fl L 71If the 72.Fl R 73option is specified, all symbolic links are followed. 74.It Fl P 75If the 76.Fl R 77option is specified, no symbolic links are followed. 78.It Fl R 79Change the modes of the file hierarchies rooted in the files 80instead of just the files themselves. 81.It Fl f 82Do not display a diagnostic message if 83.Nm 84could not modify the mode for 85.Va file . 86.It Fl v 87Cause 88.Nm 89to be verbose, showing files as the mode is modified. 90.El 91.Pp 92Symbolic links do not have modes, so unless the 93.Fl H 94or 95.Fl L 96option is set, 97.Nm 98on a symbolic link always succeeds and has no effect. 99The 100.Fl H , 101.Fl L 102and 103.Fl P 104options are ignored unless the 105.Fl R 106option is specified. 107In addition, these options override each other and the 108command's actions are determined by the last one specified. 109.Pp 110Only the owner of a file or the super-user is permitted to change 111the mode of a file. 112.Sh DIAGNOSTICS 113The 114.Nm 115utility exits 0 on success, and >0 if an error occurs. 116.Sh MODES 117Modes may be absolute or symbolic. 118An absolute mode is an octal number constructed from the sum of 119one or more of the following values: 120.Pp 121.Bl -tag -width 6n -compact -offset indent 122.It Li 4000 123(the set-user-ID-on-execution bit) Executable files with this bit set 124will run with effective uid set to the uid of the file owner. 125Directories with the set-user-id bit set will force all files and 126sub-directories created in them to be owned by the directory owner 127and not by the uid of the creating process, if the underlying file 128system supports this feature: see 129.Xr chmod 2 130and the 131.Ar suiddir 132option to 133.Xr mount 8 . 134.It Li 2000 135(the set-group-ID-on-execution bit) Executable files with this bit set 136will run with effective gid set to the gid of the file owner. 137.It Li 1000 138(the sticky bit) 139When set on a directory, unprivileged users can delete and rename 140only those files in the directory that are owned by them, regardless of 141the permissions on the directory. Under 142.Fx , 143the sticky bit is 144ignored for executable files and may only be set for directories (see 145.Xr sticky 8 ). 146.It Li 0400 147Allow read by owner. 148.It Li 0200 149Allow write by owner. 150.It Li 0100 151For files, allow execution by owner. For directories, allow the owner to 152search in the directory. 153.It Li 0040 154Allow read by group members. 155.It Li 0020 156Allow write by group members. 157.It Li 0010 158For files, allow execution by group members. For directories, allow 159group members to search in the directory. 160.It Li 0004 161Allow read by others. 162.It Li 0002 163Allow write by others. 164.It Li 0001 165For files, allow execution by others. For directories allow others to 166search in the directory. 167.El 168.Pp 169For example, the absolute mode that permits read, write and execute by 170the owner, read and execute by group members, read and execute by 171others, and no set-uid or set-gid behaviour is 755 172(400+200+100+040+010+004+001). 173.Pp 174The symbolic mode is described by the following grammar: 175.Bd -literal -offset indent 176mode ::= clause [, clause ...] 177clause ::= [who ...] [action ...] action 178action ::= op [perm ...] 179who ::= a | u | g | o 180op ::= + | \- | = 181perm ::= r | s | t | w | x | X | u | g | o 182.Ed 183.Pp 184The 185.Ar who 186symbols ``u'', ``g'', and ``o'' specify the user, group, and other parts 187of the mode bits, respectively. 188The 189.Ar who 190symbol ``a'' is equivalent to ``ugo''. 191.Pp 192The 193.Ar perm 194symbols represent the portions of the mode bits as follows: 195.Pp 196.Bl -tag -width Ds -compact -offset indent 197.It r 198The read bits. 199.It s 200The set-user-ID-on-execution and set-group-ID-on-execution bits. 201.It t 202The sticky bit. 203.It w 204The write bits. 205.It x 206The execute/search bits. 207.It X 208The execute/search bits if the file is a directory or any of the 209execute/search bits are set in the original (unmodified) mode. 210Operations with the 211.Ar perm 212symbol ``X'' are only meaningful in conjunction with the 213.Ar op 214symbol ``+'', and are ignored in all other cases. 215.It u 216The user permission bits in the mode of the original file. 217.It g 218The group permission bits in the mode of the original file. 219.It o 220The other permission bits in the mode of the original file. 221.El 222.Pp 223The 224.Ar op 225symbols represent the operation performed, as follows: 226.Bl -tag -width 4n 227.It + 228If no value is supplied for 229.Ar perm , 230the ``+'' operation has no effect. 231If no value is supplied for 232.Ar who , 233each permission bit specified in 234.Ar perm , 235for which the corresponding bit in the file mode creation mask 236is clear, is set. 237Otherwise, the mode bits represented by the specified 238.Ar who 239and 240.Ar perm 241values are set. 242.It \&\- 243If no value is supplied for 244.Ar perm , 245the ``\-'' operation has no effect. 246If no value is supplied for 247.Ar who , 248each permission bit specified in 249.Ar perm , 250for which the corresponding bit in the file mode creation mask 251is clear, is cleared. 252Otherwise, the mode bits represented by the specified 253.Ar who 254and 255.Ar perm 256values are cleared. 257.It = 258The mode bits specified by the 259.Ar who 260value are cleared, or, if no who value is specified, the owner, group 261and other mode bits are cleared. 262Then, if no value is supplied for 263.Ar who , 264each permission bit specified in 265.Ar perm , 266for which the corresponding bit in the file mode creation mask 267is clear, is set. 268Otherwise, the mode bits represented by the specified 269.Ar who 270and 271.Ar perm 272values are set. 273.El 274.Pp 275Each 276.Ar clause 277specifies one or more operations to be performed on the mode 278bits, and each operation is applied to the mode bits in the 279order specified. 280.Pp 281Operations upon the other permissions only (specified by the symbol 282``o'' by itself), in combination with the 283.Ar perm 284symbols ``s'' or ``t'', are ignored. 285.Sh EXAMPLES 286.Bl -tag -width "u=rwx,go=u-w" -compact 287.It Li 644 288make a file readable by anyone and writable by the owner only. 289.Pp 290.It Li go-w 291deny write permission to group and others. 292.Pp 293.It Li =rw,+X 294set the read and write permissions to the usual defaults, but 295retain any execute permissions that are currently set. 296.Pp 297.It Li +X 298make a directory or file searchable/executable by everyone if it is 299already searchable/executable by anyone. 300.Pp 301.It Li 755 302.It Li u=rwx,go=rx 303.It Li u=rwx,go=u-w 304make a file readable/executable by everyone and writable by the owner only. 305.Pp 306.It Li go= 307clear all mode bits for group and others. 308.Pp 309.It Li g=u-w 310set the group bits equal to the user bits, but clear the group write bit. 311.El 312.Sh BUGS 313There's no 314.Ar perm 315option for the naughty bits. 316.Sh COMPATIBILITY 317The 318.Fl v 319option is non-standard and its use in scripts is not recommended. 320.Sh SEE ALSO 321.Xr chflags 1 , 322.Xr install 1 , 323.Xr chmod 2 , 324.Xr stat 2 , 325.Xr umask 2 , 326.Xr fts 3 , 327.Xr setmode 3 , 328.Xr symlink 7 , 329.Xr chown 8 , 330.Xr mount 8 , 331.Xr sticky 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 339symbols 340.Dq t 341and 342.Dq X 343which are not included in that standard. 344.Sh HISTORY 345A 346.Nm 347command appeared in 348.At v1 . 349