1CHMOD(2)                   Linux Programmer's Manual                  CHMOD(2)
2
3
4

NAME

6       chmod, fchmod, fchmodat - change permissions of a file
7

SYNOPSIS

9       #include <sys/stat.h>
10
11       int chmod(const char *pathname, mode_t mode);
12       int fchmod(int fd, mode_t mode);
13
14       #include <fcntl.h>           /* Definition of AT_* constants */
15       #include <sys/stat.h>
16
17       int fchmodat(int dirfd, const char *pathname, mode_t mode, int flags);
18
19   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
20
21       fchmod():
22           Since glibc 2.24:
23               _POSIX_C_SOURCE >= 199309L
24           Glibc 2.19 to 2.23
25               _POSIX_C_SOURCE
26           Glibc 2.16 to 2.19:
27               _BSD_SOURCE || _POSIX_C_SOURCE
28           Glibc 2.12 to 2.16:
29               _BSD_SOURCE || _XOPEN_SOURCE >= 500 ||
30                   _POSIX_C_SOURCE >= 200809L
31           Glibc 2.11 and earlier:
32               _BSD_SOURCE || _XOPEN_SOURCE >= 500
33
34       fchmodat():
35           Since glibc 2.10:
36               _POSIX_C_SOURCE >= 200809L
37           Before glibc 2.10:
38               _ATFILE_SOURCE
39

DESCRIPTION

41       The  chmod()  and fchmod() system calls change a files mode bits.  (The
42       file mode consists of the file permission bits  plus  the  set-user-ID,
43       set-group-ID,  and sticky bits.)  These system calls differ only in how
44       the file is specified:
45
46       * chmod() changes the mode of the  file  specified  whose  pathname  is
47         given in pathname, which is dereferenced if it is a symbolic link.
48
49       * fchmod()  changes  the  mode of the file referred to by the open file
50         descriptor fd.
51
52       The new file mode is specified in mode, which is a bit mask created  by
53       ORing together zero or more of the following:
54
55       S_ISUID  (04000)  set-user-ID   (set   process  effective  user  ID  on
56                         execve(2))
57
58       S_ISGID  (02000)  set-group-ID  (set  process  effective  group  ID  on
59                         execve(2);   mandatory   locking,   as  described  in
60                         fcntl(2); take a new file's group from parent  direc‐
61                         tory, as described in chown(2) and mkdir(2))
62
63       S_ISVTX  (01000)  sticky bit (restricted deletion flag, as described in
64                         unlink(2))
65
66       S_IRUSR  (00400)  read by owner
67
68       S_IWUSR  (00200)  write by owner
69
70       S_IXUSR  (00100)  execute/search by owner ("search" applies for  direc‐
71                         tories,  and  means that entries within the directory
72                         can be accessed)
73
74       S_IRGRP  (00040)  read by group
75
76       S_IWGRP  (00020)  write by group
77
78       S_IXGRP  (00010)  execute/search by group
79
80       S_IROTH  (00004)  read by others
81
82       S_IWOTH  (00002)  write by others
83
84       S_IXOTH  (00001)  execute/search by others
85
86       The effective UID of the calling process must match the  owner  of  the
87       file,  or  the  process  must  be  privileged  (Linux: it must have the
88       CAP_FOWNER capabili