1.\" $OpenBSD: chmod.1,v 1.44 2024/08/01 14:30:17 jmc Exp $ 2.\" $NetBSD: chmod.1,v 1.8 1995/03/21 09:02:07 cgd Exp $ 3.\" 4.\" Copyright (c) 1989, 1990, 1993, 1994 5.\" The Regents of the University of California. All rights reserved. 6.\" 7.\" This code is derived from software contributed to Berkeley by 8.\" the Institute of Electrical and Electronics Engineers, Inc. 9.\" 10.\" Redistribution and use in source and binary forms, with or without 11.\" modification, are permitted provided that the following conditions 12.\" are met: 13.\" 1. Redistributions of source code must retain the above copyright 14.\" notice, this list of conditions and the following disclaimer. 15.\" 2. Redistributions in binary form must reproduce the above copyright 16.\" notice, this list of conditions and the following disclaimer in the 17.\" documentation and/or other materials provided with the distribution. 18.\" 3. Neither the name of the University nor the names of its contributors 19.\" may be used to endorse or promote products derived from this software 20.\" without specific prior written permission. 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" SUCH DAMAGE. 33.\" 34.\" @(#)chmod.1 8.4 (Berkeley) 3/31/94 35.\" 36.Dd $Mdocdate: August 1 2024 $ 37.Dt CHMOD 1 38.Os 39.Sh NAME 40.Nm chmod 41.Nd change file modes 42.Sh SYNOPSIS 43.Nm chmod 44.Op Fl h 45.Oo 46.Fl R 47.Op Fl H | L | P 48.Oc 49.Ar mode 50.Ar 51.Sh DESCRIPTION 52The 53.Nm 54utility modifies the file mode bits of the listed files 55as specified by the 56.Ar mode 57operand. 58The mode of a file dictates its permissions, among other attributes. 59.Pp 60The options are as follows: 61.Bl -tag -width Ds 62.It Fl H 63If the 64.Fl R 65option is also specified, symbolic links on the command line are followed. 66Symbolic links encountered in the tree traversal are not followed. 67.It Fl h 68Treat symbolic links like other files: modify links instead of 69following them. 70The 71.Fl h 72and 73.Fl R 74options are mutually exclusive. 75.It Fl L 76If the 77.Fl R 78option is also specified, all symbolic links are followed. 79.It Fl P 80If the 81.Fl R 82option is also specified, no symbolic links are followed. 83.It Fl R 84Recurse. 85Where 86.Ar file 87is a directory, 88change the mode of the directory and all the files and directories 89in the file hierarchy below it. 90.El 91.Pp 92Symbolic links have modes, 93but those modes have no effect on the kernel's access checks. 94The 95.Fl H , 96.Fl L , 97and 98.Fl P 99options are ignored unless the 100.Fl R 101option is specified; 102if none of them are given, 103the default is to not follow symbolic links. 104In addition, these options override each other and the 105command's actions are determined by the last one specified. 106.Pp 107Only the file's owner or the superuser is permitted to change 108the mode of a file. 109.Ss Absolute modes 110Absolute modes are specified according to the following format: 111.Bd -filled -offset indent 112.Nm chmod 113.Ar nnnn 114.Ar 115.Ed 116.Pp 117An absolute mode is an octal number (specified as 118.Ar nnnn , 119where 120.Ar n 121is a number from 0 to 7) constructed by ORing 122any of the following values: 123.Pp 124.Bl -tag -width 6n -compact -offset indent 125.It Li 0400 126Allow read by owner. 127.It Li 0200 128Allow write by owner. 129.It Li 0100 130Allow execution (or search in directories) by owner. 131.It Li 0700 132Allow read, write, and execute/search by owner. 133.It Li 0040 134Allow read by group. 135.It Li 0020 136Allow write by group. 137.It Li 0010 138Allow execution (or search in directories) by group. 139.It Li 0070 140Allow read, write, and execute/search by group. 141.It Li 0004 142Allow read by others. 143.It Li 0002 144Allow write by others. 145.It Li 0001 146Allow execution (or search in directories) by others. 147.It Li 0007 148Allow read, write, and execute/search by others. 149.El 150.Pp 151In addition to the file permission modes, the following mode bits are 152available: 153.Pp 154.Bl -tag -width 6n -compact -offset indent 155.It Li 4000 156Set-user-ID on execution. 157.It Li 2000 158Set-group-ID on execution. 159.It Li 1000 160Enable sticky bit; see 161.Xr sticky 8 162and 163.Xr chmod 2 . 164.El 165.Pp 166The execute bit for a directory is often referred to as the 167.Dq search 168bit. 169In order to access a file, a user must have execute permission in each 170directory leading up to it in the filesystem hierarchy. 171For example, to access the file 172.Pa /bin/ls , 173execute permission is needed on 174.Pa / , 175.Pa /bin , 176and, of course, the 177.Pa ls 178binary itself. 179.Ss Symbolic modes 180Symbolic modes are specified according to the following format: 181.Bd -filled -offset indent 182.Nm chmod 183.Sm off 184.Op Ar who 185.Ar op 186.Oo Ar perm Oc , Ar ... 187.Sm on 188.Ar 189.Ed 190.Pp 191The 192.Ar who 193symbols indicate whose permissions are to be changed or assigned: 194.Pp 195.Bl -tag -width 4n -compact -offset indent 196.It u 197User (owner) permissions. 198.It g 199Group permissions. 200.It o 201Others permissions. 202.It a 203All of the above. 204.El 205.Pp 206Do not confuse the 207.Sq o 208symbol with 209.Dq owner . 210It is the user bit, 211.Sq u , 212that refers to the owner of the file. 213.Pp 214The 215.Ar op 216symbols represent the operation performed, as follows: 217.Bl -tag -width 4n -offset indent 218.It + 219If no value is supplied for 220.Ar perm , 221the 222.Sq + 223operation 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 239.Sq \- 240operation has no effect. 241If 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 cleared. 247Otherwise, the mode bits represented by the specified 248.Ar who 249and 250.Ar perm 251values are cleared. 252.It = 253The mode bits specified by the 254.Ar who 255value are cleared or, if no 256.Ar who 257value is specified, the user, group 258and other mode bits are cleared. 259Then, if no value is supplied for 260.Ar who , 261each permission bit specified in 262.Ar perm , 263for which the corresponding bit in the file mode creation mask 264is clear, is set. 265Otherwise, the mode bits represented by the specified 266.Ar who 267and 268.Ar perm 269values are set. 270.El 271.Pp 272The 273.Ar perm 274(permission symbols) represent the portions of the mode bits as follows: 275.Pp 276.Bl -tag -width Ds -compact -offset indent 277.It r 278Read bits. 279.It s 280Set-user-ID and set-group-ID on execution bits. 281.It t 282Sticky bit. 283.It w 284Write bits. 285.It x 286Execute/search bits. 287.It X 288The execute/search bits if the file is a directory or any of the 289execute/search bits are set in the original (unmodified) mode. 290.It u 291User permission bits in the mode of the original file. 292.It g 293Group permission bits in the mode of the original file. 294.It o 295Other permission bits in the mode of the original file. 296.El 297.Pp 298Each clause (given in a comma-delimited list on the command line) specifies 299one or more operations to be performed on the mode bits, and each operation is 300applied in the order specified. 301.Pp 302Operations upon the 303.Dq other 304permissions (specified by the symbol 305.Sq o 306by itself), in combination with the 307.Ar perm 308symbols 309.Sq s 310or 311.Sq t , 312are ignored. 313.Sh EXIT STATUS 314.Ex -std chmod 315.Sh EXAMPLES 316Set file readable by anyone and writable by the owner only: 317.Pp 318.Dl $ chmod 644 file 319.Pp 320Deny write permission to group and others: 321.Pp 322.Dl $ chmod go-w file 323.Pp 324Set the read and write permissions to the usual defaults, but 325retain any execute permissions that are currently set: 326.Pp 327.Dl $ chmod =rwX file 328.Pp 329Make a directory or file searchable/executable by everyone if it is 330already searchable/executable by anyone: 331.Pp 332.Dl $ chmod +X file 333.Pp 334Any of these commands will make a file readable/executable by everyone and 335writable by the owner only: 336.Bd -literal -offset indent 337$ chmod 755 file 338$ chmod u=rwx,go=rx file 339$ chmod u=rwx,go=u-w file 340.Ed 341.Pp 342Clear all mode bits for group and others: 343.Pp 344.Dl $ chmod go= file 345.Pp 346Set the group bits equal to the user bits, but clear the group write bit: 347.Pp 348.Dl $ chmod g=u-w file 349.Sh SEE ALSO 350.Xr chflags 1 , 351.Xr chgrp 1 , 352.Xr find 1 , 353.Xr install 1 , 354.Xr chmod 2 , 355.Xr stat 2 , 356.Xr umask 2 , 357.Xr fts_open 3 , 358.Xr setmode 3 , 359.Xr symlink 7 , 360.Xr chown 8 , 361.Xr sticky 8 362.Sh STANDARDS 363The 364.Nm 365utility is compliant with the 366.St -p1003.1-2024 367specification. 368.Pp 369The flags 370.Op Fl HhLP 371are extensions to that specification. 372.Pp 373The 374.Sq t 375perm symbol (sticky bit) is marked by 376.St -p1003.1-2024 377as being an 378X/Open System Interfaces 379option. 380.Sh HISTORY 381A 382.Nm 383command appeared in 384.At v1 . 385.Sh BUGS 386There's no 387.Ar perm 388option for the naughty bits. 389