1chmod(2)                      System Calls Manual                     chmod(2)
2
3
4

NAME

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

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

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

DESCRIPTION

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