]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - bin/chmod/chmod.1
This commit was generated by cvs2svn to compensate for changes in r51848,
[FreeBSD/FreeBSD.git] / bin / chmod / chmod.1
1 .\" Copyright (c) 1989, 1990, 1993, 1994
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" This code is derived from software contributed to Berkeley by
5 .\" the Institute of Electrical and Electronics Engineers, Inc.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\"    notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\"    notice, this list of conditions and the following disclaimer in the
14 .\"    documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\"    must display the following acknowledgement:
17 .\"     This product includes software developed by the University of
18 .\"     California, Berkeley and its contributors.
19 .\" 4. Neither the name of the University nor the names of its contributors
20 .\"    may be used to endorse or promote products derived from this software
21 .\"    without specific prior written permission.
22 .\"
23 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .\" SUCH DAMAGE.
34 .\"
35 .\"     @(#)chmod.1     8.4 (Berkeley) 3/31/94
36 .\" $FreeBSD$
37 .\"
38 .Dd March 31, 1994
39 .Dt CHMOD 1
40 .Os
41 .Sh NAME
42 .Nm chmod
43 .Nd change file modes
44 .Sh SYNOPSIS
45 .Nm chmod
46 .Oo
47 .Fl f
48 .Fl R
49 .Op Fl H | Fl L | Fl P
50 .Oc
51 .Ar mode
52 .Ar file ...
53 .Sh DESCRIPTION
54 The
55 .Nm
56 utility modifies the file mode bits of the listed files
57 as specified by the
58 .Ar mode
59 operand.
60 .Pp
61 The options are as follows:
62 .Bl -tag -width Ds
63 .It Fl H
64 If the
65 .Fl R
66 option is specified, symbolic links on the command line are followed.
67 (Symbolic links encountered in the tree traversal are not followed.)
68 .It Fl L
69 If the
70 .Fl R
71 option is specified, all symbolic links are followed.
72 .It Fl P
73 If the
74 .Fl R
75 option is specified, no symbolic links are followed.
76 .It Fl R
77 Change the modes of the file hierarchies rooted in the files
78 instead of just the files themselves.
79 .It Fl f
80 Do not display a diagnostic message if
81 .Nm
82 could not modify the mode for
83 .Va file .
84 .El
85 .Pp
86 Symbolic links do not have modes, so unless the
87 .Fl H
88 or
89 .Fl L
90 option is set,
91 .Nm
92 on a symbolic link always succeeds and has no effect.
93 The
94 .Fl H ,
95 .Fl L
96 and
97 .Fl P
98 options are ignored unless the
99 .Fl R
100 option is specified.
101 In addition, these options override each other and the
102 command's actions are determined by the last one specified.
103 .Pp
104 Only the owner of a file or the super-user is permitted to change
105 the mode of a file.
106 .Sh DIAGNOSTICS
107 The
108 .Nm
109 utility exits 0 on success, and >0 if an error occurs.
110 .Sh MODES
111 Modes may be absolute or symbolic.
112 An absolute mode is an octal number constructed from the sum of
113 one or more of the following values:
114 .Pp
115 .Bl -tag -width 6n -compact -offset indent
116 .It Li 4000
117 (the set-user-ID-on-execution bit) Executable files with this bit set 
118 will run with effective uid set to the uid of the file owner.
119 Directories with the set-user-id bit set will force all files and 
120 sub-directories created in them to be owned by the directory owner 
121 and not by the uid of the creating process, if the underlying file 
122 system supports this feature: see 
123 .Xr chmod 2
124 and the 
125 .Ar suiddir
126 option to
127 .Xr mount 8 .
128 .It Li 2000
129 (the set-group-ID-on-execution bit)  Executable files with this bit set 
130 will run with effective gid set to the gid of the file owner.  
131 .It Li 1000
132 (the sticky bit)  
133 When set on a directory, unprivileged users can delete and rename
134 only those files in the directory that are owned by them, regardless of 
135 the permissions on the directory.  Under FreeBSD, the sticky bit is 
136 ignored for executable files and may only be set for directories (see 
137 .Xr sticky 8 ).
138 .It Li 0400
139 Allow read by owner.
140 .It Li 0200
141 Allow write by owner.
142 .It Li 0100
143 For files, allow execution by owner.  For directories, allow the owner to 
144 search in the directory.
145 .It Li 0040
146 Allow read by group members.
147 .It Li 0020
148 Allow write by group members.
149 .It Li 0010
150 For files, allow execution by group members.  For directories, allow 
151 group members to search in the directory.
152 .It Li 0004
153 Allow read by others.
154 .It Li 0002
155 Allow write by others.
156 .It Li 0001
157 For files, allow execution by others.  For directories allow others to
158 search in the directory.
159 .El
160 .Pp
161 For example, the absolute mode that permits read, write and execute by 
162 the owner, read and execute by group members, read and execute by 
163 others, and no set-uid or set-gid behaviour is 755 
164 (400+200+100+040+010+004+001).
165 .Pp
166 The symbolic mode is described by the following grammar:
167 .Bd -literal -offset indent
168 mode         ::= clause [, clause ...]
169 clause       ::= [who ...] [action ...] last_action
170 action       ::= op [perm ...]
171 last_action  ::= op [perm ...]
172 who          ::= a | u | g | o
173 op           ::= + | \- | =
174 perm         ::= r | s | t | w | x | X | u | g | o
175 .Ed
176 .Pp
177 The
178 .Ar who
179 symbols ``u'', ``g'', and ``o'' specify the user, group, and other parts
180 of the mode bits, respectively.
181 The
182 .Ar who
183 symbol ``a'' is equivalent to ``ugo''.
184 .Pp
185 .ne 1i
186 The
187 .Ar perm
188 symbols represent the portions of the mode bits as follows:
189 .Pp
190 .Bl -tag -width Ds -compact -offset indent
191 .It r
192 The read bits.
193 .It s
194 The set-user-ID-on-execution and set-group-ID-on-execution bits.
195 .It t
196 The sticky bit.
197 .It w
198 The write bits.
199 .It x
200 The execute/search bits.
201 .It X
202 The execute/search bits if the file is a directory or any of the
203 execute/search bits are set in the original (unmodified) mode.
204 Operations with the
205 .Ar perm
206 symbol ``X'' are only meaningful in conjunction with the
207 .Ar op
208 symbol ``+'', and are ignored in all other cases.
209 .It u
210 The user permission bits in the mode of the original file.
211 .It g
212 The group permission bits in the mode of the original file.
213 .It o
214 The other permission bits in the mode of the original file.
215 .El
216 .Pp
217 The
218 .Ar op
219 symbols represent the operation performed, as follows:
220 .Bl -tag -width 4n
221 .It +
222 If no value is supplied for
223 .Ar perm ,
224 the ``+'' operation has no effect.
225 If no value is supplied for
226 .Ar who ,
227 each permission bit specified in
228 .Ar perm ,
229 for which the corresponding bit in the file mode creation mask
230 is clear, is set.
231 Otherwise, the mode bits represented by the specified
232 .Ar who
233 and
234 .Ar perm
235 values are set.
236 .It \&\-
237 If no value is supplied for
238 .Ar perm ,
239 the ``\-'' operation has no effect.
240 If no value is supplied for
241 .Ar who ,
242 each permission bit specified in
243 .Ar perm ,
244 for which the corresponding bit in the file mode creation mask
245 is clear, is cleared.
246 Otherwise, the mode bits represented by the specified
247 .Ar who
248 and
249 .Ar perm
250 values are cleared.
251 .It =
252 The mode bits specified by the
253 .Ar who
254 value are cleared, or, if no who value is specified, the owner, group
255 and other mode bits are cleared.
256 Then, if no value is supplied for
257 .Ar who ,
258 each permission bit specified in
259 .Ar perm ,
260 for which the corresponding bit in the file mode creation mask
261 is clear, is set.
262 Otherwise, the mode bits represented by the specified
263 .Ar who
264 and
265 .Ar perm
266 values are set.
267 .El
268 .Pp
269 Each
270 .Ar clause
271 specifies one or more operations to be performed on the mode
272 bits, and each operation is applied to the mode bits in the
273 order specified.
274 .Pp
275 Operations upon the other permissions only (specified by the symbol
276 ``o'' by itself), in combination with the
277 .Ar perm
278 symbols ``s'' or ``t'', are ignored.
279 .Sh EXAMPLES
280 .Bl -tag -width "u=rwx,go=u-w" -compact
281 .It Li 644
282 make a file readable by anyone and writable by the owner only.
283 .Pp
284 .It Li go-w
285 deny write permission to group and others.
286 .Pp
287 .It Li =rw,+X
288 set the read and write permissions to the usual defaults, but
289 retain any execute permissions that are currently set.
290 .Pp
291 .It Li +X
292 make a directory or file searchable/executable by everyone if it is
293 already searchable/executable by anyone.
294 .Pp
295 .It Li 755
296 .It Li u=rwx,go=rx
297 .It Li u=rwx,go=u-w
298 make a file readable/executable by everyone and writable by the owner only.
299 .Pp
300 .It Li go=
301 clear all mode bits for group and others.
302 .Pp
303 .It Li g=u-w
304 set the group bits equal to the user bits, but clear the group write bit.
305 .El
306 .Sh BUGS
307 There's no
308 .Ar perm
309 option for the naughty bits.
310 .Sh SEE ALSO
311 .Xr chflags 1 ,
312 .Xr install 1 ,
313 .Xr chmod 2 ,
314 .Xr stat 2 ,
315 .Xr umask 2 ,
316 .Xr fts 3 ,
317 .Xr setmode 3 ,
318 .Xr symlink 7 ,
319 .Xr chown 8 ,
320 .Xr mount 8 ,
321 .Xr sticky 8
322 .Sh STANDARDS
323 The
324 .Nm
325 utility is expected to be
326 .St -p1003.2
327 compatible with the exception of the
328 .Ar perm
329 symbols
330 .Dq t
331 and
332 .Dq X
333 which are not included in that standard.
334 .Sh HISTORY
335 A
336 .Nm
337 command appeared in
338 .At v1 .