chmod(2) System Calls Manual chmod(2) chmod, fchmod, fchmodat - C (libc, -lc) #include int chmod(const char *path, mode_t mode); int fchmod(int fd, mode_t mode); #include /* AT_* */ #include int fchmodat(int dirfd, const char *path, mode_t mode, int flags); glibc (. feature_test_macros(7)): fchmod(): glibc 2.24: _POSIX_C_SOURCE >= 199309L glibc 2.19 glibc 2.23 _POSIX_C_SOURCE glibc 2.16 glibc 2.19: _BSD_SOURCE || _POSIX_C_SOURCE glibc 2.12 glibc 2.16: _BSD_SOURCE || _XOPEN_SOURCE >= 500 || _POSIX_C_SOURCE >= 200809L glibc 2.11 : _BSD_SOURCE || _XOPEN_SOURCE >= 500 fchmodat(): glibc 2.10: _POSIX_C_SOURCE >= 200809L glibc 2.10: _ATFILE_SOURCE chmod() fchmod() ( set-user-ID, set-group-ID ) : o chmod() changes the mode of the file specified whose pathname is given in path, which is dereferenced if it is a symbolic link. o fchown() , fd. mode , : S_ISUID (04000) set-user-ID ( execve(2)) S_ISGID (02000) set-group-ID ( execve(2); , fcntl(2); , chown(2) mkdir(2)) S_ISVTX (01000) ( , unlink(2)) S_IRUSR (00400) S_IWUSR (00200) S_IXUSR (00100) ("" , ) S_IRGRP (00040) - S_IWGRP (00020) - S_IXGRP (00010) - S_IROTH (00004) S_IWOTH (00002) S_IXOTH (00001) (UID) UID (Linux: CAP_FOWNER). (Linux: CAP_FSETID), - ID , S_ISGID , . set-user-ID set-group-ID ( Linux , CAP_FSETID). , . , set-user-ID set-group-ID inode(7). NFS , , . , . fchmodat() fchmodat() chmod(), , . If path is relative, then it is interpreted relative to the directory referred to by the file descriptor dirfd (rather than relative to the current working directory of the calling process, as is done by chmod() for a relative pathname). If path is relative and dirfd is the special value AT_FDCWD, then path is interpreted relative to the current working directory of the calling process (like chmod()). If path is absolute, then dirfd is ignored. flags can either be 0, or include the following flags: AT_EMPTY_PATH (since Linux 6.6) If path is an empty string, operate on the file referred to by dirfd (which may have been obtained using the open(2) O_PATH flag). In this case, dirfd can refer to any type of file, not just a directory. If dirfd is AT_FDCWD, the call operates on the current working directory. This flag is Linux-specific; define _GNU_SOURCE to obtain its definition. AT_SYMLINK_NOFOLLOW If path is a symbolic link, do not dereference it: instead operate on the link itself. openat(2) fchmodat(). 0. -1, errno . , . chmod() : EACCES - (. path_resolution(7).) EBADF (fchmod()) fd . EBADF (fchmodat()) path is relative but dirfd is neither AT_FDCWD nor a valid file descriptor. EFAULT path . EINVAL (fchmodat()) flags. EIO -. ELOOP path . ENAMETOOLONG path . ENOENT . ENOMEM . ENOTDIR . ENOTDIR (fchmodat()) path is relative and dirfd is a file descriptor referring to a file other than a directory. ENOTSUP (fchmodat()) flags AT_SYMLINK_NOFOLLOW, . EPERM UID , (Linux: CAP_FOWNER). EPERM (immutable) ( FS_IOC_SETFLAGS(2const)). EROFS , . C fchmodat() GNU C, POSIX-. Linux , flags. glibc On older kernels where fchmodat() is unavailable, the glibc wrapper function falls back to the use of chmod(). When path is a relative pathname, glibc constructs a pathname based on the symbolic link in /proc/self/fd that corresponds to the dirfd argument. POSIX.1-2024. chmod() SVr4, POSIX.1-1988, 4.4BSD. fchmod() SVr4, 4.4BSD, SUSv1, POSIX.1-1996. fchmodat() POSIX.1-2008. Linux 2.6.16, glibc 2.4. AT_SYMLINK_NOFOLLOW POSIX.1-2008, glibc 2.32, Linux 6.5. chmod(1), chown(2), execve(2), open(2), stat(2), inode(7), path_resolution(7), symlink(7) () Azamat Hackimov , Dmitriy S. Seregin , Dmitry Bolkhovskikh , Katrin Kutepova , Yuri Kozlov ; GNU (GNU General Public License - GPL, 3 ) , - . - , , () () () . Linux man-pages 6.18 8 2026 . chmod(2)