1.\" $NetBSD: chmod.1,v 1.29 2023/05/05 04:14:02 kre Exp $ 2.\" 3.\" Copyright (c) 1989, 1990, 1993, 1994 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" This code is derived from software contributed to Berkeley by 7.\" the Institute of Electrical and Electronics Engineers, Inc. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 3. Neither the name of the University nor the names of its contributors 18.\" may be used to endorse or promote products derived from this software 19.\" without specific prior written permission. 20.\" 21.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31.\" SUCH DAMAGE. 32.\" 33.\" @(#)chmod.1 8.4 (Berkeley) 3/31/94 34.\" 35.Dd August 11, 2016 36.Dt CHMOD 1 37.Os 38.Sh NAME 39.Nm chmod 40.Nd change file modes 41.Sh SYNOPSIS 42.Nm 43.Oo 44.Fl R 45.Op Fl H | Fl L | Fl P 46.Oc 47.Op Fl dfh 48.Ar mode 49.Ar 50.Nm 51.Oo 52.Fl R 53.Op Fl H | Fl L | Fl P 54.Oc 55.Op Fl dfh 56.Fl Fl reference=rfile 57.Ar 58.Sh DESCRIPTION 59The 60.Nm 61utility modifies the file mode bits of the listed files 62as specified by the 63.Ar mode 64operand, or 65copied from a reference 66.Ar rfile , 67as specified with the 68.Fl Fl reference 69argument. 70.Pp 71The options are as follows: 72.Bl -tag -width Ds 73.It Fl H 74If the 75.Fl R 76option is specified, symbolic links on the command line are followed. 77(Symbolic links encountered in the tree traversal are not followed.) 78.It Fl L 79If the 80.Fl R 81option is specified, all symbolic links are followed. 82.It Fl P 83If the 84.Fl R 85option is specified, no symbolic links are followed. 86.It Fl R 87Change the modes of the file hierarchies rooted in the 88.Ar file Ns s 89instead of just the files themselves. 90.It Fl d 91Do not attempt to change the mode of a 92.Ar file 93if its mode is already as requested. 94.It Fl f 95Do not display a diagnostic message or modify the exit status if 96.Nm 97fails to change the mode of a 98.Ar file . 99.It Fl h 100If 101.Ar file 102is symbolic link, the mode of the link is changed. 103.El 104.Pp 105The 106.Fl H , 107.Fl L 108and 109.Fl P 110options are ignored unless the 111.Fl R 112option is specified. 113In addition, these options override each other and the 114command's actions are determined by the last one specified. 115The default is as if the 116.Fl P 117option had been specified. 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 chmod 123.Sh MODES 124Modes may be absolute or symbolic. 125An absolute mode is an octal number constructed by 126.Em or Ap ing 127the following values: 128.Pp 129.Bl -tag -width 6n -compact -offset indent 130.It Li 4000 131set-user-ID-on-execution 132.It Li 2000 133set-group-ID-on-execution 134.It Li 1000 135sticky bit, see 136.Xr chmod 2 137.It Li 0400 138read by owner 139.It Li 0200 140write by owner 141.It Li 0100 142execute (or search for directories) by owner 143.It Li 0070 144read, write, execute/search by group 145.It Li 0007 146read, write, execute/search by others 147.El 148.Pp 149The read, write, and execute/search values for group and others 150are encoded as described for owner. 151.Pp 152The symbolic mode is described by the following grammar: 153.Bd -literal -offset indent 154mode ::= clause [, clause ...] 155clause ::= [who ...] [action ...] last_action 156action ::= op [perm ...] 157last_action ::= op [perm ...] 158who ::= a | u | g | o 159op ::= + | \- | = 160perm ::= r | s | t | w | x | X | u | g | o 161.Ed 162.Pp 163The 164.Ar who 165symbols ``u'', ``g'', and ``o'' specify the user, group, and other parts 166of the mode bits, respectively. 167The 168.Ar who 169symbol ``a'' is equivalent to ``ugo''. 170.Pp 171The 172.Ar perm 173symbols represent the portions of the mode bits as follows: 174.Pp 175.Bl -tag -width Ds -compact -offset indent 176.It r 177The read bits. 178.It s 179The set-user-ID-on-execution and set-group-ID-on-execution bits. 180.It t 181The sticky bit. 182.It w 183The write bits. 184.It x 185The execute/search bits. 186.It X 187The execute/search bits if the file is a directory or any of the 188execute/search bits are set in the original (unmodified) mode. 189Operations with the 190.Ar perm 191symbol ``X'' are only meaningful in conjunction with the 192.Ar op 193symbol ``+'', and are ignored in all other cases. 194.It u 195The user permission bits in the mode of the original file. 196.It g 197The group permission bits in the mode of the original file. 198.It o 199The other permission bits in the mode of the original file. 200.El 201.Pp 202The 203.Ar op 204symbols represent the operation performed, as follows: 205.Bl -tag -width 4n 206.It + 207If no value is supplied for 208.Ar perm , 209the ``+'' operation has no effect. 210If no value is supplied for 211.Ar who , 212each permission bit specified in 213.Ar perm , 214for which the corresponding bit in the file mode creation mask 215is clear, is set. 216Otherwise, the mode bits represented by the specified 217.Ar who 218and 219.Ar perm 220values are set. 221.It \&\- 222If no value is supplied for 223.Ar perm , 224the ``\-'' operation has no effect. 225If no value is supplied for 226.Ar who , 227each permission bit specified in 228.Ar perm , 229for which the corresponding bit in the file mode creation mask 230is clear, is cleared. 231Otherwise, the mode bits represented by the specified 232.Ar who 233and 234.Ar perm 235values are cleared. 236.It = 237The mode bits specified by the 238.Ar who 239value are cleared, or, if no who value is specified, the owner, group 240and other mode bits are cleared. 241Then, if no value is supplied for 242.Ar who , 243each permission bit specified in 244.Ar perm , 245for which the corresponding bit in the file mode creation mask 246is clear, is set. 247Otherwise, the mode bits represented by the specified 248.Ar who 249and 250.Ar perm 251values are set. 252.El 253.Pp 254Each 255.Ar clause 256specifies one or more operations to be performed on the mode 257bits, and each operation is applied to the mode bits in the 258order specified. 259.Pp 260Operations upon the other permissions only (specified by the symbol 261``o'' by itself), in combination with the 262.Ar perm 263symbols ``s'' or ``t'', are ignored. 264.Sh EXAMPLES 265.Bl -tag -width "u=rwx,go=u-w" -compact 266.It Li 644 267make a file readable by anyone and writable by the owner only. 268.Pp 269.It Li go-w 270deny write permission to group and others. 271.Pp 272.It Li =rw,+X 273set the read and write permissions to the usual defaults, but 274retain any execute permissions that are currently set. 275.Pp 276.It Li +X 277make a directory or file searchable/executable by everyone if it is 278already searchable/executable by anyone. 279.Pp 280.It Li 755 281.It Li u=rwx,go=rx 282.It Li u=rwx,go=u-w 283make a file readable/executable by everyone and writable by the owner only. 284.Pp 285.It Li go= 286clear all mode bits for group and others. 287.Pp 288.It Li g=u-w 289set the group bits equal to the user bits, but clear the group write bit. 290.El 291.Sh SEE ALSO 292.Xr chflags 1 , 293.Xr install 1 , 294.Xr chmod 2 , 295.Xr stat 2 , 296.Xr umask 2 , 297.Xr fts 3 , 298.Xr setmode 3 , 299.Xr symlink 7 , 300.Xr chown 8 301.Sh STANDARDS 302The 303.Nm 304utility is expected to be 305.St -p1003.2-92 306compatible with the exception of the 307.Ar perm 308symbol 309.Dq t 310which is not included in that standard. 311.Sh HISTORY 312A 313.Nm 314utility appeared in 315.At v1 . 316.Sh BUGS 317There's no 318.Ar perm 319option for the naughty bits. 320