1.\" Copyright (c) 1980, 1991 Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. All advertising materials mentioning features or use of this software 13.\" must display the following acknowledgement: 14.\" This product includes software developed by the University of 15.\" California, Berkeley and its contributors. 16.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" @(#)chown.2 6.7 (Berkeley) 3/10/91 33.\" 34.Dd March 10, 1991 35.Dt CHOWN 2 36.Os BSD 4 37.Sh NAME 38.Nm chown , 39.Nm fchown 40.Nd change owner and group of a file 41.Sh SYNOPSIS 42.Fd #include <unistd.h> 43.Ft int 44.Fn chown "const char *path" "uid_t owner" "gid_t group" 45.Ft int 46.Fn fchown "int fd" "int owner" "int group" 47.Sh DESCRIPTION 48The owner ID and group ID of the file 49named by 50.Fa path 51or referenced by 52.Fa fd 53is changed as specified by the arguments 54.Fa owner 55and 56.Fa group . 57The owner of a file may change the 58.Fa group 59to a group of which 60he or she is a member, 61but the change 62.Fa owner 63capability is restricted to the super-user. 64.Pp 65.Fn Chown 66clears the set-user-id and set-group-id bits 67on the file 68to prevent accidental or mischievious creation of 69set-user-id and set-group-id programs. 70.Pp 71.Fn Fchown 72is particularly useful when used in conjunction 73with the file locking primitives (see 74.Xr flock 2 ) . 75.Pp 76One of the owner or group id's 77may be left unchanged by specifying it as -1. 78.Pp 79If the final component of 80.Fa path 81is a symbolic link, 82the ownership and group of the symbolic link is changed, 83not the ownership and group of the file or directory to which it points. 84.Sh RETURN VALUES 85Zero is returned if the operation was successful; 86-1 is returned if an error occurs, with a more specific 87error code being placed in the global variable 88.Va errno . 89.Sh ERRORS 90.Fn Chown 91will fail and the file will be unchanged if: 92.Bl -tag -width Er 93.It Bq Er ENOTDIR 94A component of the path prefix is not a directory. 95.It Bq Er EINVAL 96The pathname contains a character with the high-order bit set. 97.It Bq Er ENAMETOOLONG 98A component of a pathname exceeded 255 characters, 99or an entire path name exceeded 1023 characters. 100.It Bq Er ENOENT 101The named file does not exist. 102.It Bq Er EACCES 103Search permission is denied for a component of the path prefix. 104.It Bq Er ELOOP 105Too many symbolic links were encountered in translating the pathname. 106.It Bq Er EPERM 107The effective user ID is not the super-user. 108.It Bq Er EROFS 109The named file resides on a read-only file system. 110.It Bq Er EFAULT 111.Fa Path 112points outside the process's allocated address space. 113.It Bq Er EIO 114An I/O error occurred while reading from or writing to the file system. 115.El 116.Pp 117.Fn Fchown 118will fail if: 119.Bl -tag -width Er 120.It Bq Er EBADF 121.Fa Fd 122does not refer to a valid descriptor. 123.It Bq Er EINVAL 124.Fa Fd 125refers to a socket, not a file. 126.It Bq Er EPERM 127The effective user ID is not the super-user. 128.It Bq Er EROFS 129The named file resides on a read-only file system. 130.It Bq Er EIO 131An I/O error occurred while reading from or writing to the file system. 132.El 133.Sh SEE ALSO 134.Xr chown 8 , 135.Xr chgrp 1 , 136.Xr chmod 2 , 137.Xr flock 2 138.Sh STANDARDS 139.Fn Chown 140is expected to conform to IEEE Std 1003.1-1988 141.Pq Dq Tn POSIX . 142.Sh HISTORY 143The 144.Fn fchown 145function call 146appeared in 147.Bx 4.2 . 148