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