1.\" $NetBSD: chmod.1,v 1.28 2017/07/04 06:47:27 wiz 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 fh 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 fh 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 files 88instead of just the files themselves. 89.It Fl f 90Do not display a diagnostic message or modify the exit status if 91.Nm 92fails to change the mode of a file. 93.It Fl h 94If 95.Ar file 96is symbolic link, the mode of the link is changed. 97.El 98.Pp 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. 109The default is as if the 110.Fl P 111option had been specified. 112.Pp 113Only the owner of a file or the super-user is permitted to change 114the mode of a file. 115.Sh EXIT STATUS 116.Ex -std chmod 117.Sh MODES 118Modes may be absolute or symbolic. 119An absolute mode is an octal number constructed by 120.Em or Ap ing 121the following values: 122.Pp 123.Bl -tag -width 6n -compact -offset indent 124.It Li 4000 125set-user-ID-on-execution 126.It Li 2000 127set-group-ID-on-execution 128.It Li 1000 129sticky bit, see 130.Xr chmod 2 131.It Li 0400 132read by owner 133.It Li 0200 134write by owner 135.It Li 0100 136execute (or search for directories) by owner 137.It Li 0070 138read, write, execute/search by group 139.It Li 0007 140read, write, execute/search by others 141.El 142.Pp 143The read, write, and execute/search values for group and others 144are encoded as described for owner. 145.Pp 146The symbolic mode is described by the following grammar: 147.Bd -literal -offset indent 148mode ::= clause [, clause ...] 149clause ::= [who ...] [action ...] last_action 150action ::= op [perm ...] 151last_action ::= op [perm ...] 152who ::= a | u | g | o 153op ::= + | \- | = 154perm ::= r | s | t | w | x | X | u | g | o 155.Ed 156.Pp 157The 158.Ar who 159symbols ``u'', ``g'', and ``o'' specify the user, group, and other parts 160of the mode bits, respectively. 161The 162.Ar who 163symbol ``a'' is equivalent to ``ugo''. 164.Pp 165The 166.Ar perm 167symbols represent the portions of the mode bits as follows: 168.Pp 169.Bl -tag -width Ds -compact -offset indent 170.It r 171The read bits. 172.It s 173The set-user-ID-on-execution and set-group-ID-on-execution bits. 174.It t 175The sticky bit. 176.It w 177The write bits. 178.It x 179The execute/search bits. 180.It X 181The execute/search bits if the file is a directory or any of the 182execute/search bits are set in the original (unmodified) mode. 183Operations with the 184.Ar perm 185symbol ``X'' are only meaningful in conjunction with the 186.Ar op 187symbol ``+'', and are ignored in all other cases. 188.It u 189The user permission bits in the mode of the original file. 190.It g 191The group permission bits in the mode of the original file. 192.It o 193The other permission bits in the mode of the original file. 194.El 195.Pp 196The 197.Ar op 198symbols represent the operation performed, as follows: 199.Bl -tag -width 4n 200.It + 201If no value is supplied for 202.Ar perm , 203the ``+'' operation has no effect. 204If no value is supplied for 205.Ar who , 206each permission bit specified in 207.Ar perm , 208for which the corresponding bit in the file mode creation mask 209is clear, is set. 210Otherwise, the mode bits represented by the specified 211.Ar who 212and 213.Ar perm 214values are set. 215.It \&\- 216If no value is supplied for 217.Ar perm , 218the ``\-'' operation has no effect. 219If no value is supplied for 220.Ar who , 221each permission bit specified in 222.Ar perm , 223for which the corresponding bit in the file mode creation mask 224is clear, is cleared. 225Otherwise, the mode bits represented by the specified 226.Ar who 227and 228.Ar perm 229values are cleared. 230.It = 231The mode bits specified by the 232.Ar who 233value are cleared, or, if no who value is specified, the owner, group 234and other mode bits are cleared. 235Then, if no value is supplied for 236.Ar who , 237each permission bit specified in 238.Ar perm , 239for which the corresponding bit in the file mode creation mask 240is clear, is set. 241Otherwise, the mode bits represented by the specified 242.Ar who 243and 244.Ar perm 245values are set. 246.El 247.Pp 248Each 249.Ar clause 250specifies one or more operations to be performed on the mode 251bits, and each operation is applied to the mode bits in the 252order specified. 253.Pp 254Operations upon the other permissions only (specified by the symbol 255``o'' by itself), in combination with the 256.Ar perm 257symbols ``s'' or ``t'', are ignored. 258.Sh EXAMPLES 259.Bl -tag -width "u=rwx,go=u-w" -compact 260.It Li 644 261make a file readable by anyone and writable by the owner only. 262.Pp 263.It Li go-w 264deny write permission to group and others. 265.Pp 266.It Li =rw,+X 267set the read and write permissions to the usual defaults, but 268retain any execute permissions that are currently set. 269.Pp 270.It Li +X 271make a directory or file searchable/executable by everyone if it is 272already searchable/executable by anyone. 273.Pp 274.It Li 755 275.It Li u=rwx,go=rx 276.It Li u=rwx,go=u-w 277make a file readable/executable by everyone and writable by the owner only. 278.Pp 279.It Li go= 280clear all mode bits for group and others. 281.Pp 282.It Li g=u-w 283set the group bits equal to the user bits, but clear the group write bit. 284.El 285.Sh SEE ALSO 286.Xr chflags 1 , 287.Xr install 1 , 288.Xr chmod 2 , 289.Xr stat 2 , 290.Xr umask 2 , 291.Xr fts 3 , 292.Xr setmode 3 , 293.Xr symlink 7 , 294.Xr chown 8 295.Sh STANDARDS 296The 297.Nm 298utility is expected to be 299.St -p1003.2-92 300compatible with the exception of the 301.Ar perm 302symbol 303.Dq t 304which is not included in that standard. 305.Sh HISTORY 306A 307.Nm 308utility appeared in 309.At v1 . 310.Sh BUGS 311There's no 312.Ar perm 313option for the naughty bits. 314