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