Seth Woolley's Man Viewer

Manual for chown - man 2 chown

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

CHOWN(2)                   Linux Programmer's Manual                  CHOWN(2)



NAME
       chown(1,2), fchown, lchown - change ownership of a file(1,n)

SYNOPSIS
       #include <sys/types.h>
       #include <unistd.h>

       int chown(1,2)(const char *path, uid_t owner, gid_t group);
       int fchown(int fd, uid_t owner, gid_t group);
       int lchown(const char *path, uid_t owner, gid_t group);

DESCRIPTION
       These  system calls change the owner and group of the file(1,n) specified by
       path or by  fd.   Only  a  privileged  process  (Linux:  one  with  the
       CAP_CHOWN  capability)  may change the owner of a file.  The owner of a
       file(1,n) may change the group of the file(1,n) to any group of which that  owner
       is  a  member.  A privileged process (Linux: with CAP_CHOWN) may change
       the group arbitrarily.

       If the owner or group is specified as -1, then that ID is not  changed.

       When  the  owner  or  group of an executable file(1,n) are changed by a non-
       super-user, the S_ISUID and S_ISGID mode bits are cleared.  POSIX  does
       not  specify  whether this also should happen when root does the chown(1,2);
       the Linux behaviour depends on the kernel version.  In case of  a  non-
       group-executable  file(1,n)  (with  clear(1,3x,3x clrtobot) S_IXGRP bit) the S_ISGID bit indi-
       cates mandatory locking, and is not cleared by a chown(1,2).


RETURN VALUE
       On success, zero is returned.  On error(8,n), -1 is returned, and  errno  is
       set(7,n,1 builtins) appropriately.

ERRORS
       Depending  on  the file(1,n) system, other errors can be returned.  The more
       general errors for chown(1,2) are listed below.

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

       EFAULT path points outside your accessible address space.

       ELOOP  Too many symbolic links were encountered in(1,8) resolving path.

       ENAMETOOLONG
              path is too long.

       ENOENT The file(1,n) does not exist.

       ENOMEM Insufficient kernel memory was available.

       ENOTDIR
              A component of the path prefix is not a directory.

       EPERM  The  calling  process did not have the required permissions (see
              above) to change owner and/or group.

       EROFS  The named(5,8) file(1,n) resides on a read-only file(1,n) system.

       The general errors for fchown are listed below:

       EBADF  The descriptor is not valid.

       EIO    A low-level I/O error(8,n) occurred while modifying the inode.

       ENOENT See above.

       EPERM  See above.

       EROFS  See above.

NOTES
       In versions of Linux prior to 2.1.81 (and distinct from 2.1.46),  chown(1,2)
       did  not  follow symbolic links.  Since Linux 2.1.81, chown(1,2) does follow
       symbolic links, and there is a new system call  lchown  that  does  not
       follow symbolic links.  Since Linux 2.1.86, this new call (that has the
       same semantics as the old chown(1,2)) has got the same syscall  number,  and
       chown(1,2) got the newly introduced number.

       The  prototype  for  fchown is only available if(3,n) _BSD_SOURCE is defined
       (either explicitly, or implicitly, by  not  defining  _POSIX_SOURCE  or
       compiling with the -ansi flag).

CONFORMING TO
       The  chown(1,2) call conforms to SVr4, SVID, POSIX, X/OPEN.  The 4.4BSD ver-
       sion(1,3,5) can only be used by the superuser (that is, ordinary users(1,5)  cannot
       give  away files).  SVr4 documents EINVAL, EINTR, ENOLINK and EMULTIHOP
       returns, but no ENOMEM.  POSIX.1 does  not  document  ENOMEM  or  ELOOP
       error(8,n) conditions.

       The fchown call conforms to 4.4BSD and SVr4.  SVr4 documents additional
       EINVAL, EIO, EINTR, and ENOLINK error(8,n) conditions.

RESTRICTIONS
       The chown(1,2)() semantics are deliberately violated  on  NFS  file(1,n)  systems
       which  have  UID  mapping  enabled.  Additionally, the semantics of all
       system calls which access(2,5)  the  file(1,n)  contents  are  violated,  because
       chown(1,2)()  may  cause  immediate access(2,5) revocation on already open(2,3,n) files.
       Client side caching may lead to a delay between the time(1,2,n)  where  owner-
       ship  have  been  changed to allow access(2,5) for a user and the time(1,2,n) where
       the file(1,n) can actually be accessed by the user on other clients.

SEE ALSO
       chmod(1,2)(2), flock(1,2)(2), path_resolution(2)



Linux 2.6.7                       2004-06-23                          CHOWN(2)

References for this manual (incoming links)