1 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" Modified by Michael Haardt <michael@moria.de>
26 .\" Modified 1993-07-21 by Rik Faith <faith@cs.unc.edu>
27 .\" Modified 1997-01-12 by Michael Haardt
28 .\" <michael@cantor.informatik.rwth-aachen.de>: NFS details
29 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
31 .TH CHMOD 2 2010-09-26 "Linux" "Linux Programmer's Manual"
33 chmod, fchmod \- change permissions of a file
35 .B #include <sys/stat.h>
37 .BI "int chmod(const char *" path ", mode_t " mode );
39 .BI "int fchmod(int " fd ", mode_t " mode );
42 Feature Test Macro Requirements for glibc (see
43 .BR feature_test_macros (7)):
51 _XOPEN_SOURCE\ >=\ 500 ||
52 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
54 || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200809L
59 These system calls change the permissions of a file.
60 They differ only in how the file is specified:
63 changes the permissions of the file specified whose pathname is given in
65 which is dereferenced if it is a symbolic link.
68 changes the permissions of the file referred to by the open file descriptor
71 The new file permissions are specified in
73 which is a bit mask created by ORing together zero or
74 more of the following:
76 .BR S_ISUID " (04000)"
77 set-user-ID (set process effective user ID on
80 .BR S_ISGID " (02000)"
81 set-group-ID (set process effective group ID on
83 mandatory locking, as described in
85 take a new file's group from parent directory, as described in
90 .BR S_ISVTX " (01000)"
91 sticky bit (restricted deletion flag, as described in
94 .BR S_IRUSR " (00400)"
97 .BR S_IWUSR " (00200)"
100 .BR S_IXUSR " (00100)"
101 execute/search by owner ("search" applies for directories,
102 and means that entries within the directory can be accessed)
104 .BR S_IRGRP " (00040)"
107 .BR S_IWGRP " (00020)"
110 .BR S_IXGRP " (00010)"
111 execute/search by group
113 .BR S_IROTH " (00004)"
116 .BR S_IWOTH " (00002)"
119 .BR S_IXOTH " (00001)"
120 execute/search by others
122 The effective UID of the calling process must match the owner of the file,
123 or the process must be privileged (Linux: it must have the
127 If the calling process is not privileged (Linux: does not have the
129 capability), and the group of the file does not match
130 the effective group ID of the process or one of its
131 supplementary group IDs, the
133 bit will be turned off,
134 but this will not cause an error to be returned.
136 As a security measure, depending on the filesystem,
137 the set-user-ID and set-group-ID execution bits
138 may be turned off if a file is written.
139 (On Linux this occurs if the writing process does not have the
142 On some filesystems, only the superuser can set the sticky bit,
143 which may have a special meaning.
144 For the sticky bit, and for set-user-ID and set-group-ID bits on
148 On NFS filesystems, restricting the permissions will immediately influence
149 already open files, because the access control is done on the server, but
150 open files are maintained by the client.
151 Widening the permissions may be
152 delayed for other clients if attribute caching is enabled on them.
154 On success, zero is returned.
155 On error, \-1 is returned, and
157 is set appropriately.
159 Depending on the filesystem, other errors can be returned.
160 The more general errors for
165 Search permission is denied on a component of the path prefix.
167 .BR path_resolution (7).)
171 points outside your accessible address space.
174 An I/O error occurred.
177 Too many symbolic links were encountered in resolving
185 The file does not exist.
188 Insufficient kernel memory was available.
191 A component of the path prefix is not a directory.
194 The effective UID does not match the owner of the file,
195 and the process is not privileged (Linux: it does not have the
200 The named file resides on a read-only filesystem.
202 The general errors for
220 4.4BSD, SVr4, POSIX.1-2001.
227 .BR path_resolution (7)