1.\" $NetBSD: chmod.1,v 1.15 2000/10/14 18:45:03 bjh21 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. All advertising materials mentioning features or use of this software 18.\" must display the following acknowledgement: 19.\" This product includes software developed by the University of 20.\" California, Berkeley and its contributors. 21.\" 4. Neither the name of the University nor the names of its contributors 22.\" may be used to endorse or promote products derived from this software 23.\" without specific prior written permission. 24.\" 25.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35.\" SUCH DAMAGE. 36.\" 37.\" @(#)chmod.1 8.4 (Berkeley) 3/31/94 38.\" 39.Dd October 11, 2000 40.Dt CHMOD 1 41.Os 42.Sh NAME 43.Nm chmod 44.Nd change file modes 45.Sh SYNOPSIS 46.Nm 47.Oo 48.Fl R 49.Op Fl H | Fl L | Fl P 50.Oc 51.Op Fl h 52.Ar mode 53.Ar 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.) 69.It Fl L 70If the 71.Fl R 72option is specified, all symbolic links are followed. 73.It Fl P 74If the 75.Fl R 76option is specified, no symbolic links are followed. 77.It Fl R 78Change the modes of the file hierarchies rooted in the files 79instead of just the files themselves. 80.It Fl h 81If 82.Ar file 83is symbolic link, the mode of the link is changed. 84.El 85.Pp 86If the option 87.Fl h 88is not given, unless the 89.Fl H 90or 91.Fl L 92option is set, 93.Nm 94on a symbolic link always succeeds and has no effect. 95The 96.Fl H , 97.Fl L 98and 99.Fl P 100options are ignored unless the 101.Fl R 102option is specified. 103In addition, these options override each other and the 104command's actions are determined by the last one specified. 105.Pp 106Only the owner of a file or the super-user is permitted to change 107the mode of a file. 108.Pp 109.Sh EXIT STATUS 110The 111.Nm 112utility exits 0 on success, and >0 if an error occurs. 113.Sh MODES 114Modes may be absolute or symbolic. 115An absolute mode is an octal number constructed by 116.Em or Ap ing 117the following values: 118.Pp 119.Bl -tag -width 6n -compact -offset indent 120.It Li 4000 121set-user-ID-on-execution 122.It Li 2000 123set-group-ID-on-execution 124.It Li 1000 125sticky bit, see 126.Xr chmod 2 127.It Li 0400 128read by owner 129.It Li 0200 130write by owner 131.It Li 0100 132execute (or search for directories) by owner 133.It Li 0070 134read, write, execute/search by group 135.It Li 0007 136read, write, execute/search by others 137.El 138.Pp 139The read, write, and execute/search values for group and others 140are encoded as described for owner. 141.Pp 142The symbolic mode is described by the following grammar: 143.Bd -literal -offset indent 144mode ::= clause [, clause ...] 145clause ::= [who ...] [action ...] last_action 146action ::= op [perm ...] 147last_action ::= op [perm ...] 148who ::= a | u | g | o 149op ::= + | \- | = 150perm ::= r | s | t | w | x | X | u | g | o 151.Ed 152.Pp 153The 154.Ar who 155symbols ``u'', ``g'', and ``o'' specify the user, group, and other parts 156of the mode bits, respectively. 157The 158.Ar who 159symbol ``a'' is equivalent to ``ugo''. 160.Pp 161.ne 1i 162The 163.Ar perm 164symbols represent the portions of the mode bits as follows: 165.Pp 166.Bl -tag -width Ds -compact -offset indent 167.It r 168The read bits. 169.It s 170The set-user-ID-on-execution and set-group-ID-on-execution bits. 171.It t 172The sticky bit. 173.It w 174The write bits. 175.It x 176The execute/search bits. 177.It X 178The execute/search bits if the file is a directory or any of the 179execute/search bits are set in the original (unmodified) mode. 180Operations with the 181.Ar perm 182symbol ``X'' are only meaningful in conjunction with the 183.Ar op 184symbol ``+'', and are ignored in all other cases. 185.It u 186The user permission bits in the mode of the original file. 187.It g 188The group permission bits in the mode of the original file. 189.It o 190The other permission bits in the mode of the original file. 191.El 192.Pp 193The 194.Ar op 195symbols represent the operation performed, as follows: 196.Bl -tag -width 4n 197.It + 198If no value is supplied for 199.Ar perm , 200the ``+'' operation has no effect. 201If no value is supplied for 202.Ar who , 203each permission bit specified in 204.Ar perm , 205for which the corresponding bit in the file mode creation mask 206is clear, is set. 207Otherwise, the mode bits represented by the specified 208.Ar who 209and 210.Ar perm 211values are set. 212.It \&\- 213If no value is supplied for 214.Ar perm , 215the ``\-'' operation has no effect. 216If no value is supplied for 217.Ar who , 218each permission bit specified in 219.Ar perm , 220for which the corresponding bit in the file mode creation mask 221is clear, is cleared. 222Otherwise, the mode bits represented by the specified 223.Ar who 224and 225.Ar perm 226values are cleared. 227.It = 228The mode bits specified by the 229.Ar who 230value are cleared, or, if no who value is specified, the owner, group 231and other mode bits are cleared. 232Then, if no value is supplied for 233.Ar who , 234each permission bit specified in 235.Ar perm , 236for which the corresponding bit in the file mode creation mask 237is clear, is set. 238Otherwise, the mode bits represented by the specified 239.Ar who 240and 241.Ar perm 242values are set. 243.El 244.Pp 245Each 246.Ar clause 247specifies one or more operations to be performed on the mode 248bits, and each operation is applied to the mode bits in the 249order specified. 250.Pp 251Operations upon the other permissions only (specified by the symbol 252``o'' by itself), in combination with the 253.Ar perm 254symbols ``s'' or ``t'', are ignored. 255.Sh EXAMPLES 256.Bl -tag -width "u=rwx,go=u-w" -compact 257.It Li 644 258make a file readable by anyone and writable by the owner only. 259.Pp 260.It Li go-w 261deny write permission to group and others. 262.Pp 263.It Li =rw,+X 264set the read and write permissions to the usual defaults, but 265retain any execute permissions that are currently set. 266.Pp 267.It Li +X 268make a directory or file searchable/executable by everyone if it is 269already searchable/executable by anyone. 270.Pp 271.It Li 755 272.It Li u=rwx,go=rx 273.It Li u=rwx,go=u-w 274make a file readable/executable by everyone and writable by the owner only. 275.Pp 276.It Li go= 277clear all mode bits for group and others. 278.Pp 279.It Li g=u-w 280set the group bits equal to the user bits, but clear the group write bit. 281.El 282.Sh BUGS 283There's no 284.Ar perm 285option for the naughty bits. 286.Sh SEE ALSO 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