maint: update all FSF copyright year lists to include 2010
[platform/upstream/coreutils.git] / man / chmod.x
1 '\" Copyright (C) 1998-1999, 2001, 2006-2007, 2009-2010 Free Software
2 '\" Foundation, Inc.
3 '\"
4 '\" This is free software.  You may redistribute copies of it under the terms
5 '\" of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
6 '\" There is NO WARRANTY, to the extent permitted by law.
7 [NAME]
8 chmod \- change file mode bits
9 [DESCRIPTION]
10 This manual page
11 documents the GNU version of
12 .BR chmod .
13 .B chmod
14 changes the file mode bits of each given file according to
15 .IR mode ,
16 which can be either a symbolic representation of changes to make, or
17 an octal number representing the bit pattern for the new mode bits.
18 .PP
19 The format of a symbolic mode is [\c
20 \fBugoa\fP.\|.\|.][[\fB+-=\fP][\fIperms\fP.\|.\|.].\|.\|.],
21 where
22 .I "perms"
23 is either zero or more letters from the set
24 \fBrwxXst\fP, or a single letter from the set \fBugo\fP.
25 Multiple symbolic
26 modes can be given, separated by commas.
27 .PP
28 A combination of the letters \fBugoa\fP controls which users' access
29 to the file will be changed: the user who owns it (\fBu\fP), other
30 users in the file's group (\fBg\fP), other users not in the file's
31 group (\fBo\fP), or all users (\fBa\fP).  If none of these are given,
32 the effect is as if \fBa\fP were
33 given, but bits that are set in the umask are not affected.
34 .PP
35 The operator \fB+\fP causes the selected file mode bits to be added to
36 the existing file mode bits of each file; \fB-\fP causes them to be
37 removed; and \fB=\fP causes them to be added and causes unmentioned
38 bits to be removed except that a directory's unmentioned set user and
39 group ID bits are not affected.
40 .PP
41 The letters \fBrwxXst\fP select file mode bits for the affected users:
42 read (\fBr\fP), write (\fBw\fP), execute (or search for directories)
43 (\fBx\fP), execute/search only if the file is a directory or already
44 has execute permission for some user (\fBX\fP), set user or group ID
45 on execution (\fBs\fP), restricted deletion flag or sticky bit
46 (\fBt\fP).  Instead of one or more of these letters, you can specify
47 exactly one of the letters \fBugo\fP: the permissions granted to the
48 user who owns the file (\fBu\fP), the permissions granted to other
49 users who are members of the file's group (\fBg\fP),
50 and the permissions granted to users that are in neither of the two preceding
51 categories (\fBo\fP).
52 .PP
53 A numeric mode is from one to four octal digits (0\-7), derived by
54 adding up the bits with values 4, 2, and 1.  Omitted digits are
55 assumed to be leading zeros.
56 The first digit selects the set user ID (4) and set group ID (2) and
57 restricted deletion or sticky (1) attributes.  The second digit
58 selects permissions for the user who owns the file: read (4), write (2),
59 and execute (1); the third selects permissions for other users in the
60 file's group, with the same values; and the fourth for other users not
61 in the file's group, with the same values.
62 .PP
63 .B chmod
64 never changes the permissions of symbolic links; the
65 .B chmod
66 system call cannot change their permissions.  This is not a problem
67 since the permissions of symbolic links are never used.
68 However, for each symbolic link listed on the command line,
69 .B chmod
70 changes the permissions of the pointed-to file.
71 In contrast,
72 .B chmod
73 ignores symbolic links encountered during recursive directory
74 traversals.
75 .SH "SETUID AND SETGID BITS"
76 .B chmod
77 clears the set-group-ID bit of a
78 regular file if the file's group ID does not match the user's
79 effective group ID or one of the user's supplementary group IDs,
80 unless the user has appropriate privileges.  Additional restrictions
81 may cause the set-user-ID and set-group-ID bits of
82 .I MODE
83 or
84 .I RFILE
85 to be ignored.  This behavior depends on the policy and
86 functionality of the underlying
87 .B chmod
88 system call.  When in
89 doubt, check the underlying system behavior.
90 .PP
91 .B chmod
92 preserves a directory's set-user-ID and set-group-ID bits unless you
93 explicitly specify otherwise.  You can set or clear the bits with
94 symbolic modes like
95 .B u+s
96 and
97 .BR g\-s ,
98 and you can set (but not clear) the bits with a numeric mode.
99 .SH "RESTRICTED DELETION FLAG OR STICKY BIT"
100 The restricted deletion flag or sticky bit is a single bit, whose
101 interpretation depends on the file type.  For directories, it prevents
102 unprivileged users from removing or renaming a file in the directory
103 unless they own the file or the directory; this is called the
104 .I "restricted deletion flag"
105 for the directory, and is commonly found on world-writable directories
106 like \fB/tmp\fP.  For regular files on some older systems, the bit
107 saves the program's text image on the swap device so it will load more
108 quickly when run; this is called the
109 .IR "sticky bit" .
110 .SH OPTIONS
111 [SEE ALSO]
112 chmod(2)