1 '\" Copyright (C) 1998-2023 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 never changes the permissions of symbolic links; the 64 .B chmod 65 system call cannot change their permissions. This is not a problem 66 since the permissions of symbolic links are never used. 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. 74 .SH "SETUID AND SETGID BITS" 75 .B chmod 76 clears the set-group-ID bit of a 77 regular file if the file's group ID does not match the user's 78 effective group ID or one of the user's supplementary group IDs, 79 unless the user has appropriate privileges. Additional restrictions 80 may cause the set-user-ID and set-group-ID bits of 81 .I MODE 82 or 83 .I RFILE 84 to be ignored. This behavior depends on the policy and 85 functionality of the underlying 86 .B chmod 87 system call. When in 88 doubt, check the underlying system behavior. 89 .PP 90 For directories 91 .B chmod 92 preserves 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 To clear these bits for directories with a numeric mode requires 99 an additional leading zero like 100 .BR 00755 , 101 leading minus like 102 .BR \-6000 , 103 or leading equals like 104 .BR =755 . 105 .SH "RESTRICTED DELETION FLAG OR STICKY BIT" 106 The restricted deletion flag or sticky bit is a single bit, whose 107 interpretation depends on the file type. For directories, it prevents 108 unprivileged users from removing or renaming a file in the directory 109 unless they own the file or the directory; this is called the 110 .I "restricted deletion flag" 111 for the directory, and is commonly found on world-writable directories 112 like \fB/tmp\fP. For regular files on some older systems, the bit 113 saves the program's text image on the swap device so it will load more 114 quickly when run; this is called the 115 .IR "sticky bit" . 116 .SH OPTIONS 117 [SEE ALSO] 118 chmod(2) 119