1 '\" Copyright (C) 1998-2024 Free Software Foundation, Inc.
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.
7 chmod \- change file mode bits
10 documents the GNU version of
13 changes the file mode bits of each given file according to
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.
18 The format of a symbolic mode is [\c
19 \fBugoa\fP.\|.\|.][[\fB-+=\fP][\fIperms\fP.\|.\|.].\|.\|.],
22 is either zero or more letters from the set
23 \fBrwxXst\fP, or a single letter from the set \fBugo\fP.
25 modes can be given, separated by commas.
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.
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.
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
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.
63 doesn't change the permissions of symbolic links; the
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,
69 changes the permissions of the pointed-to file.
72 ignores symbolic links encountered during recursive directory
73 traversals. Options that modify this behavior are described in the
76 .SH "SETUID AND SETGID BITS"
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
86 to be ignored. This behavior depends on the policy and
87 functionality of the underlying
90 doubt, check the underlying system behavior.
94 preserves set-user-ID and set-group-ID bits unless you
95 explicitly specify otherwise. You can set or clear the bits with
100 To clear these bits for directories with a numeric mode requires
101 an additional leading zero like
105 or leading equals like
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