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