| 1 | .\" Copyright (c) 1989, 1990 The Regents of the University of California. |
| 2 | .\" All rights reserved. |
| 3 | .\" |
| 4 | .\" %sccs.include.redist.man% |
| 5 | .\" |
| 6 | .\" @(#)chmod.1 6.13 (Berkeley) %G% |
| 7 | .\" |
| 8 | .Dd |
| 9 | .Dt CHMOD 1 |
| 10 | .Os BSD 4.4 |
| 11 | .Sh NAME |
| 12 | .Nm chmod |
| 13 | .Nd change file modes |
| 14 | .Sh SYNOPSIS |
| 15 | .Nm chmod |
| 16 | .Op Fl R |
| 17 | .Ar mode |
| 18 | .Ar file ... |
| 19 | .Sh DESCRIPTION |
| 20 | The |
| 21 | .Nm chmod |
| 22 | utility modifies the file mode bits of the listed files |
| 23 | as specified by the |
| 24 | .Ar mode |
| 25 | operand. |
| 26 | .Pp |
| 27 | The options are as follows: |
| 28 | .Bl -tag -width Ds |
| 29 | .It Fl R |
| 30 | Traverse a file hierarchy. |
| 31 | For each file that is of type directory, |
| 32 | .Nm chmod |
| 33 | changes the mode of all files in the file hierarchy below it followed |
| 34 | by the mode of the directory itself. |
| 35 | .El |
| 36 | .Pp |
| 37 | Symbolic links are not indirected through, nor are their modes altered. |
| 38 | .Pp |
| 39 | Only the owner of a file or the super-user is permitted to change |
| 40 | the mode of a file. |
| 41 | .Pp |
| 42 | The |
| 43 | .Nm chmod |
| 44 | utility exits 0 on success, and >0 if an error occurs. |
| 45 | .Sh MODES |
| 46 | Modes may be absolute or symbolic. |
| 47 | An absolute mode is an octal number constructed by |
| 48 | .Ar or Ap ing |
| 49 | the following values: |
| 50 | .Pp |
| 51 | .Bl -tag -width 6n -compact -offset indent |
| 52 | .It Li 4000 |
| 53 | set-user-ID-on-execution |
| 54 | .It Li 2000 |
| 55 | set-group-ID-on-execution |
| 56 | .It Li 1000 |
| 57 | sticky bit, see chmod(2) |
| 58 | .It Li 0400 |
| 59 | read by owner |
| 60 | .It Li 0200 |
| 61 | write by owner |
| 62 | .It Li 0100 |
| 63 | execute (or search for directories) by owner |
| 64 | .It Li 0070 |
| 65 | read, write, execute/search by group |
| 66 | .It Li 0007 |
| 67 | read, write, execute/search by others |
| 68 | .El |
| 69 | .Pp |
| 70 | The read, write, and execute/search values for group and others |
| 71 | are encoded as described for owner. |
| 72 | .Pp |
| 73 | The symbolic mode is described by the following grammar: |
| 74 | .Bd -literal -offset indent |
| 75 | mode ::= clause [, clause ...] |
| 76 | clause ::= [who ...] [action ...] last_action |
| 77 | action ::= op [perm ...] |
| 78 | last_action ::= op [perm ...] |
| 79 | who ::= a | u | g | o |
| 80 | op ::= + | \- | = |
| 81 | perm ::= r | s | t | w | X | x | u | g | o |
| 82 | .Ed |
| 83 | .Pp |
| 84 | The |
| 85 | .Ar who |
| 86 | symbols ``u'', ``g'', and ``o'' specify the user, group, and other parts |
| 87 | of the mode bits, respectively. |
| 88 | The |
| 89 | .Ar who |
| 90 | symbol ``a'' is equivalent to ``ugo''. |
| 91 | .Pp |
| 92 | The |
| 93 | .Ar perm |
| 94 | symbols represent the portions of the mode bits as follows: |
| 95 | .Pp |
| 96 | .Bl -tag -width Ds -compact -offset indent |
| 97 | .It r |
| 98 | The read bits. |
| 99 | .It s |
| 100 | The set-user-ID-on-execution and set-group-ID-on-execution bits. |
| 101 | .It t |
| 102 | The sticky bit. |
| 103 | .It w |
| 104 | The write bits. |
| 105 | .It x |
| 106 | The execute/search bits. |
| 107 | .It X |
| 108 | The execute/search bits if the file is a directory or any of the |
| 109 | execute/search bits are set in the original (unmodified) mode. |
| 110 | Operations with the |
| 111 | .Ar perm |
| 112 | symbol ``X'' are only meaningful in conjunction with the |
| 113 | .Ar op |
| 114 | symbol ``+'', and it is ignored in all other cases. |
| 115 | .El |
| 116 | .Pp |
| 117 | The |
| 118 | .Ar op |
| 119 | symbols represent the operation performed, as follows: |
| 120 | .Bl -tag -width 4n |
| 121 | .It + |
| 122 | If no value is supplied for |
| 123 | .Ar perm , |
| 124 | the ``+'' operation has no effect. |
| 125 | If no value is supplied for |
| 126 | .Ar who , |
| 127 | each permission bit specified in |
| 128 | .Ar perm , |
| 129 | for which the corresponding bit in the file mode creation mask |
| 130 | is clear, is set. |
| 131 | Otherwise, the mode bits represented by the specified |
| 132 | .Ar who |
| 133 | and |
| 134 | .Ar perm |
| 135 | values are set. |
| 136 | .It \&\- |
| 137 | If no value is supplied for |
| 138 | .Ar perm , |
| 139 | the ``\-'' operation has no effect. |
| 140 | If no value is supplied for |
| 141 | .Ar who , |
| 142 | the mode bits represented by |
| 143 | .Ar perm |
| 144 | are cleared for the owner, group and other permissions. |
| 145 | Otherwise, the mode bits represented by the specified |
| 146 | .Ar who |
| 147 | and |
| 148 | .Ar perm |
| 149 | values are cleared. |
| 150 | .It = |
| 151 | The mode bits specified by the |
| 152 | .Ar who |
| 153 | value are cleared, or, if no who value is specified, the owner, group |
| 154 | and other mode bits are cleared. |
| 155 | Then, if no value is supplied for |
| 156 | .Ar who , |
| 157 | each permission bit specified in |
| 158 | .Ar perm , |
| 159 | for which the corresponding bit in the file mode creation mask |
| 160 | is clear, is set. |
| 161 | Otherwise, the mode bits represented by the specified |
| 162 | .Ar who |
| 163 | and |
| 164 | .Ar perm |
| 165 | values are set. |
| 166 | .El |
| 167 | .Pp |
| 168 | Each |
| 169 | .Ar clause |
| 170 | specifies one or more operations to be performed on the mode |
| 171 | bits, and each operation is applied to the mode bits in the |
| 172 | order specified. |
| 173 | .Pp |
| 174 | Operations upon the other permissions only (specified by the symbol |
| 175 | ``o'' by itself), in combination with the |
| 176 | .Ar perm |
| 177 | symbols ``s'' or ``t'', are ignored. |
| 178 | .Sh EXAMPLES |
| 179 | .Bl -tag -width "u=rwx,go=u-w" -compact |
| 180 | .It Li 644 |
| 181 | make a file readable by anyone and writable by the owner only. |
| 182 | .Pp |
| 183 | .It Li go-w |
| 184 | deny write permission to group and others. |
| 185 | .Pp |
| 186 | .It Li =rw,+X |
| 187 | set the read and write permissions to the usual defaults, but |
| 188 | retain any execute permissions that are currently set. |
| 189 | .Pp |
| 190 | .It Li +X |
| 191 | make a directory or file searchable/executable by everyone if it is |
| 192 | already searchable/executable by anyone. |
| 193 | .Pp |
| 194 | .It Li 755 |
| 195 | .It Li u=rwx,go=rx |
| 196 | .It Li u=rwx,go=u-w |
| 197 | make a file readable/executable by everyone and writeable by the owner only. |
| 198 | .Pp |
| 199 | .It Li go= |
| 200 | clear all mode bits for group and others. |
| 201 | .Pp |
| 202 | .It Li g=u-w |
| 203 | set the group bits equal to the user bits, but clear the group write bit. |
| 204 | .El |
| 205 | .Sh BUGS |
| 206 | There's no |
| 207 | .Ar perm |
| 208 | option for the naughty bits. |
| 209 | .Sh SEE ALSO |
| 210 | .Xr install 1 , |
| 211 | .Xr chmod 2 , |
| 212 | .Xr stat 2 , |
| 213 | .Xr umask 2 , |
| 214 | .Xr fts 3 , |
| 215 | .Xr setmode 3 , |
| 216 | .Xr chown 8 |
| 217 | .Sh STANDARDS |
| 218 | The |
| 219 | .Nm chmod |
| 220 | utility is expected to be POSIX 1003.2 compatible with the exception |
| 221 | of the |
| 222 | .Ar perm |
| 223 | symbols |
| 224 | .Dq t |
| 225 | and |
| 226 | .Dq X |
| 227 | which are not included in that standard. |