chmod, fchmod, fchmodat - change permissions of a file


   #include <sys/stat.h>

   int chmod(const char *pathname, mode_t mode);
   int fchmod(int fd, mode_t mode);

   #include <fcntl.h>           /* Definition of AT_* constants */
   #include <sys/stat.h>

   int fchmodat(int dirfd, const char *pathname, mode_t mode, int flags);

   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

       /* Since glibc 2.16: */ _POSIX_C_SOURCE
           || /* Glibc versions <= 2.19: */ _BSD_SOURCE
           || /* Glibc versions <= 2.15: */ _XOPEN_SOURCE >= 500
           || /* Glibc 2.12 to 2.15: */ _POSIX_C_SOURCE >= 200809L

       Since glibc 2.10:
           _POSIX_C_SOURCE >= 200809L
       Before glibc 2.10:


   The  chmod()  and fchmod() system calls change a files mode bits.  (The
   file mode consists of the file permission bits  plus  the  set-user-ID,
   set-group-ID,  and sticky bits.)  These system calls differ only in how
   the file is specified:

   * chmod() changes the mode of the  file  specified  whose  pathname  is
     given in pathname, which is dereferenced if it is a symbolic link.

   * fchmod()  changes  the  mode of the file referred to by the open file
     descriptor fd.

   The new file mode is specified in mode, which is a bit mask created  by
   ORing together zero or more of the following:

   S_ISUID  (04000)  set-user-ID   (set   process  effective  user  ID  on

   S_ISGID  (02000)  set-group-ID  (set  process  effective  group  ID  on
                     execve(2);   mandatory   locking,   as  described  in
                     fcntl(2);  take  a  new  file's  group  from   parent
                     directory, as described in chown(2) and mkdir(2))

   S_ISVTX  (01000)  sticky bit (restricted deletion flag, as described in

   S_IRUSR  (00400)  read by owner

   S_IWUSR  (00200)  write by owner

   S_IXUSR  (00100)  execute/search  by  owner   ("search"   applies   for
                     directories,   and  means  that  entries  within  the
                     directory can be accessed)

   S_IRGRP  (00040)  read by group

   S_IWGRP  (00020)  write by group

   S_IXGRP  (00010)  execute/search by group

   S_IROTH  (00004)  read by others

   S_IWOTH  (00002)  write by others

   S_IXOTH  (00001)  execute/search by others

   The effective UID of the calling process must match the  owner  of  the
   file,  or  the  process  must  be  privileged  (Linux: it must have the
   CAP_FOWNER capability).

   If the calling process is not privileged  (Linux:  does  not  have  the
   CAP_FSETID  capability),  and  the group of the file does not match the
   effective group ID of the process or one  of  its  supplementary  group
   IDs,  the  S_ISGID  bit  will be turned off, but this will not cause an
   error to be returned.

   As a security measure, depending on the filesystem, the set-user-ID and
   set-group-ID  execution  bits  may  be turned off if a file is written.
   (On Linux, this occurs  if  the  writing  process  does  not  have  the
   CAP_FSETID  capability.)   On  some filesystems, only the superuser can
   set the sticky bit, which may have a special meaning.  For  the  sticky
   bit,  and  for  set-user-ID  and  set-group-ID bits on directories, see

   On  NFS  filesystems,  restricting  the  permissions  will  immediately
   influence already open files, because the access control is done on the
   server, but open files are maintained  by  the  client.   Widening  the
   permissions  may  be  delayed for other clients if attribute caching is
   enabled on them.

   The fchmodat() system call operates in exactly the same way as chmod(),
   except for the differences described here.

   If  the  pathname given in pathname 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 pathname is relative and dirfd is the special value  AT_FDCWD,  then
   pathname  is  interpreted  relative to the current working directory of
   the calling process (like chmod()).

   If pathname is absolute, then dirfd is ignored.

   flags can either be 0, or include the following flag:

          If pathname is a symbolic link, do not dereference  it:  instead
          operate  on  the  link  itself.   This  flag  is  not  currently

   See openat(2) for an explanation of the need for fchmodat().


   On success, zero is returned.  On error, -1 is returned, and  errno  is
   set appropriately.


   Depending  on  the filesystem, errors other than those listed below can
   be returned.

   The more general errors for chmod() are listed below:

   EACCES Search permission is denied on a component of the  path  prefix.
          (See also path_resolution(7).)

   EFAULT pathname points outside your accessible address space.

   EIO    An I/O error occurred.

   ELOOP  Too many symbolic links were encountered in resolving pathname.

          pathname is too long.

   ENOENT The file does not exist.

   ENOMEM Insufficient kernel memory was available.

          A component of the path prefix is not a directory.

   EPERM  The  effective UID does not match the owner of the file, and the
          process  is  not  privileged  (Linux:  it  does  not  have   the
          CAP_FOWNER capability).

   EROFS  The named file resides on a read-only filesystem.

   The general errors for fchmod() are listed below:

   EBADF  The file descriptor fd is not valid.

   EIO    See above.

   EPERM  See above.

   EROFS  See above.

   The  same  errors that occur for chmod() can also occur for fchmodat().
   The following additional errors can occur for fchmodat():

   EBADF  dirfd is not a valid file descriptor.

   EINVAL Invalid flag specified in flags.

          pathname is relative and dirfd is a file descriptor referring to
          a file other than a directory.

          flags specified AT_SYMLINK_NOFOLLOW, which is not supported.


   fchmodat()  was  added  to  Linux in kernel 2.6.16; library support was
   added to glibc in version 2.4.


   chmod(), fchmod(): 4.4BSD, SVr4, POSIX.1-2001i, POSIX.1-2008.

   fchmodat(): POSIX.1-2008.


   C library/kernel differences
   The GNU C library fchmodat() wrapper  function  implements  the  POSIX-
   specified  interface  described  in  this page.  This interface differs
   from the underlying Linux system call, which  does  not  have  a  flags

   Glibc notes
   On  older  kernels  where  fchmodat() is unavailable, the glibc wrapper
   function falls back to the use of chmod().  When pathname is a relative
   pathname,  glibc  constructs  a  pathname based on the symbolic link in
   /proc/self/fd that corresponds to the dirfd argument.


   chmod(1), chown(2), execve(2),  open(2),  stat(2),  path_resolution(7),


   This  page  is  part of release 4.09 of the Linux man-pages project.  A
   description of the project, information about reporting bugs,  and  the
   latest     version     of     this    page,    can    be    found    at

More Linux Commands

DBM_Filter::utf8(3pm) - filter for DBM_Filter (Man Page)....
This Filter will ensure that all data written to the DBM will be encoded in UTF-8 . This module uses the Encode module. SEE ALSO DBM_Filter, perldbmfilter, Enco

XmbLookupString(3) - obtain composed input from an input met
The XmbLookupString, XwcLookupString and Xutf8LookupString functions return the string from the input method specified in the buffer_return argument. If no stri

file(n) - Manipulate file names and attributes (Man Page)...
This command provides several operations on a files name or attributes. Name is the name of a file; if it starts with a tilde, then tilde substitution is done b

Tcl_FSSplitPath(3) - procedures to interact with any filesys
There are several reasons for calling the Tcl_FS API functions (e.g. Tcl_FSAccess and Tcl_FSStat) rather than calling system level functions like access and sta

gnutls_pkcs11_add_provider(3) - API function (Man Page).....
This function will load and add a PKCS 11 module to the module list used in gnutls. After this function is called the module will be used for PKCS 11 operations

ip-token(8) tokenized interface identifier support..........
IPv6 tokenized interface identifier support is used for assigning well-known host-part addresses to nodes whilst still obtaining a global network prefix from Ro

tk_getOpenFile(n) - pop up a dialog box for the user to sele
The procedures tk_getOpenFile and tk_getSaveFile pop up a dialog box for the user to select a file to open or save. The tk_getOpenFile command is usually associ

item_name(3menu) - get menu item name and description fields
The function item_name returns the name part of the given item. The function item_description returns the description part of the given item. RETURN VALUE These

koi8-u(7) - Ukrainian character set encoded in octal, decima
KOI8-U (KOI8 Ukrainian, described in RFC 2310) is the de-facto standard character set for encoding Ukrainian texts. KOI8-U is compatible with KOI8-R (RFC 1489)

scalbf(3) - multiply floating-point number by integral power
These functions multiply their first argument x by FLT_RADIX (probably 2) to the power of exp, that is: x * FLT_RADIX ** exp The definition of FLT_RADIX can be

vlc.1 (Manual - Linux man page)............................
This manual page documents briefly the VLC multimedia player and server. OPTIONS VLC follows the usual GNU command line syntax, with long options starting with

fts_close(3) - traverse a file hierarchy - Linux man page...
The fts functions are provided for traversing file hierarchies. A simple overview is that the fts_open() function returns a handle on a file hierarchy, which is

We can't live, work or learn in freedom unless the software we use is free.