]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - bin/chmod/chmod.1
This commit was generated by cvs2svn to compensate for changes in r49187,
[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 .\"     $Id: chmod.1,v 1.10 1998/05/19 06:24:50 jkoshy Exp $
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 R
48 .Op Fl H | Fl L | Fl P
49 .Oc
50 .Ar mode
51 .Ar file ...
52 .Sh DESCRIPTION
53 The
54 .Nm
55 utility modifies the file mode bits of the listed files
56 as specified by the
57 .Ar mode
58 operand.
59 .Pp
60 The options are as follows:
61 .Bl -tag -width Ds
62 .It Fl H
63 If the
64 .Fl R
65 option is specified, symbolic links on the command line are followed.
66 (Symbolic links encountered in the tree traversal are not followed.)
67 .It Fl L
68 If the
69 .Fl R
70 option is specified, all symbolic links are followed.
71 .It Fl P
72 If the
73 .Fl R
74 option is specified, no symbolic links are followed.
75 .It Fl R
76 Change the modes of the file hierarchies rooted in the files
77 instead of just the files themselves.
78 .El
79 .Pp
80 Symbolic links do not have modes, so unless the
81 .Fl H
82 or
83 .Fl L
84 option is set,
85 .Nm
86 on a symbolic link always succeeds and has no effect.
87 The
88 .Fl H ,
89 .Fl L
90 and
91 .Fl P
92 options are ignored unless the
93 .Fl R
94 option is specified.
95 In addition, these options override each other and the
96 command's actions are determined by the last one specified.
97 .Pp
98 Only the owner of a file or the super-user is permitted to change
99 the mode of a file.
100 .Sh DIAGNOSTICS
101 The
102 .Nm
103 utility exits 0 on success, and >0 if an error occurs.
104 .Sh MODES
105 Modes may be absolute or symbolic.
106 An absolute mode is an octal number constructed from the sum of
107 one or more of the following values:
108 .Pp
109 .Bl -tag -width 6n -compact -offset indent
110 .It Li 4000
111 (the set-user-ID-on-execution bit) Executable files with this bit set 
112 will run with effective uid set to the uid of the file owner.
113 Directories with the set-user-id bit set will force all files and 
114 sub-directories created in them to be owned by the directory owner 
115 and not by the uid of the creating process, if the underlying file 
116 system supports this feature: see 
117 .Xr chmod 2
118 and the 
119 .Ar suiddir
120 option to
121 .Xr mount 1 .
122 .It Li 2000
123 (the set-group-ID-on-execution bit)  Executable files with this bit set 
124 will run with effective gid set to the gid of the file owner.  
125 .It Li 1000
126 (the sticky bit)  
127 When set on a directory, unprivileged users can delete and rename
128 only those files in the directory that are owned by them, regardless of 
129 the permissions on the directory.  Under FreeBSD, the sticky bit is 
130 ignored for executable files and may only be set for directories (see 
131 .Xr sticky 8 ).
132 .It Li 0400
133 Allow read by owner.
134 .It Li 0200
135 Allow write by owner.
136 .It Li 0100
137 For files, allow execution by owner.  For directories, allow the owner to 
138 search in the directory.
139 .It Li 0040
140 Allow read by group members.
141 .It Li 0020
142 Allow write by group members.
143 .It Li 0010
144 For files, allow execution by group members.  For directories, allow 
145 group members to search in the directory.
146 .It Li 0004
147 Allow read by others.
148 .It Li 0002
149 Allow write by others.
150 .It Li 0001
151 For files, allow execution by others.  For directories allow others to
152 search in the directory.
153 .El
154 .Pp
155 For example, the absolute mode that permits read, write and execute by 
156 the owner, read and execute by group members, read and execute by 
157 others, and no set-uid or set-gid behaviour is 755 
158 (400+200+100+040+010+004+001).
159 .Pp
160 The symbolic mode is described by the following grammar:
161 .Bd -literal -offset indent
162 mode         ::= clause [, clause ...]
163 clause       ::= [who ...] [action ...] last_action
164 action       ::= op [perm ...]
165 last_action  ::= op [perm ...]
166 who          ::= a | u | g | o
167 op           ::= + | \- | =
168 perm         ::= r | s | t | w | x | X | u | g | o
169 .Ed
170 .Pp
171 The
172 .Ar who
173 symbols ``u'', ``g'', and ``o'' specify the user, group, and other parts
174 of the mode bits, respectively.
175 The
176 .Ar who
177 symbol ``a'' is equivalent to ``ugo''.
178 .Pp
179 .ne 1i
180 The
181 .Ar perm
182 symbols represent the portions of the mode bits as follows:
183 .Pp
184 .Bl -tag -width Ds -compact -offset indent
185 .It r
186 The read bits.
187 .It s
188 The set-user-ID-on-execution and set-group-ID-on-execution bits.
189 .It t
190 The sticky bit.
191 .It w
192 The write bits.
193 .It x
194 The execute/search bits.
195 .It X
196 The execute/search bits if the file is a directory or any of the
197 execute/search bits are set in the original (unmodified) mode.
198 Operations with the
199 .Ar perm
200 symbol ``X'' are only meaningful in conjunction with the
201 .Ar op
202 symbol ``+'', and are ignored in all other cases.
203 .It u
204 The user permission bits in the mode of the original file.
205 .It g
206 The group permission bits in the mode of the original file.
207 .It o
208 The other permission bits in the mode of the original file.
209 .El
210 .Pp
211 The
212 .Ar op
213 symbols represent the operation performed, as follows:
214 .Bl -tag -width 4n
215 .It +
216 If no value is supplied for
217 .Ar perm ,
218 the ``+'' operation has no effect.
219 If no value is supplied for
220 .Ar who ,
221 each permission bit specified in
222 .Ar perm ,
223 for which the corresponding bit in the file mode creation mask
224 is clear, is set.
225 Otherwise, the mode bits represented by the specified
226 .Ar who
227 and
228 .Ar perm
229 values are set.
230 .It \&\-
231 If no value is supplied for
232 .Ar perm ,
233 the ``\-'' operation has no effect.
234 If no value is supplied for
235 .Ar who ,
236 each permission bit specified in
237 .Ar perm ,
238 for which the corresponding bit in the file mode creation mask
239 is clear, is cleared.
240 Otherwise, the mode bits represented by the specified
241 .Ar who
242 and
243 .Ar perm
244 values are cleared.
245 .It =
246 The mode bits specified by the
247 .Ar who
248 value are cleared, or, if no who value is specified, the owner, group
249 and other mode bits are cleared.
250 Then, if no value is supplied for
251 .Ar who ,
252 each permission bit specified in
253 .Ar perm ,
254 for which the corresponding bit in the file mode creation mask
255 is clear, is set.
256 Otherwise, the mode bits represented by the specified
257 .Ar who
258 and
259 .Ar perm
260 values are set.
261 .El
262 .Pp
263 Each
264 .Ar clause
265 specifies one or more operations to be performed on the mode
266 bits, and each operation is applied to the mode bits in the
267 order specified.
268 .Pp
269 Operations upon the other permissions only (specified by the symbol
270 ``o'' by itself), in combination with the
271 .Ar perm
272 symbols ``s'' or ``t'', are ignored.
273 .Sh EXAMPLES
274 .Bl -tag -width "u=rwx,go=u-w" -compact
275 .It Li 644
276 make a file readable by anyone and writable by the owner only.
277 .Pp
278 .It Li go-w
279 deny write permission to group and others.
280 .Pp
281 .It Li =rw,+X
282 set the read and write permissions to the usual defaults, but
283 retain any execute permissions that are currently set.
284 .Pp
285 .It Li +X
286 make a directory or file searchable/executable by everyone if it is
287 already searchable/executable by anyone.
288 .Pp
289 .It Li 755
290 .It Li u=rwx,go=rx
291 .It Li u=rwx,go=u-w
292 make a file readable/executable by everyone and writable by the owner only.
293 .Pp
294 .It Li go=
295 clear all mode bits for group and others.
296 .Pp
297 .It Li g=u-w
298 set the group bits equal to the user bits, but clear the group write bit.
299 .El
300 .Sh BUGS
301 There's no
302 .Ar perm
303 option for the naughty bits.
304 .Sh SEE ALSO
305 .Xr chflags 1 ,
306 .Xr install 1 ,
307 .Xr mount 1 ,
308 .Xr chmod 2 ,
309 .Xr stat 2 ,
310 .Xr umask 2 ,
311 .Xr fts 3 ,
312 .Xr setmode 3 ,
313 .Xr symlink 7 ,
314 .Xr chown 8 ,
315 .Xr sticky 8
316 .Sh STANDARDS
317 The
318 .Nm
319 utility is expected to be
320 .St -p1003.2
321 compatible with the exception of the
322 .Ar perm
323 symbols
324 .Dq t
325 and
326 .Dq X
327 which are not included in that standard.
328 .Sh HISTORY
329 A
330 .Nm
331 command appeared in
332 .At v1 .