1 .\" $NetBSD: chown.2,v 1.36 2013/07/30 12:38:16 njoly Exp $
3 .\" Copyright (c) 1980, 1991, 1993, 1994
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)chown.2 8.4 (Berkeley) 4/19/94
40 .Nd change owner and group of a file
46 .Fn chown "const char *path" "uid_t owner" "gid_t group"
48 .Fn lchown "const char *path" "uid_t owner" "gid_t group"
50 .Fn fchown "int fd" "uid_t owner" "gid_t group"
53 .Fn fchownat "int fd" "const char *path" "uid_t owner" "gid_t group" "int flag"
55 The owner ID and group ID of the file
60 is changed as specified by the arguments
64 The owner of a file may change the
67 he or she is a member,
70 capability is restricted to the super-user.
72 When called to change the owner of a file,
80 When a called to change the group of a file,
85 clear the set-group-id
88 These actions are taken to prevent accidental or mischievous creation of
89 set-user-id and set-group-id programs.
94 except in the case where the named file is a symbolic link,
97 changes the owner and group of the link,
100 changes the owner and group of the file the link references.
103 is particularly useful when used in conjunction
104 with the file locking primitives (see
108 works the same way as
113 .Dv AT_SYMLINK_NOFOLLOW
119 In that case, it is looked up from a directory whose file
120 descriptor was passed as
122 Search permission is required on this directory.
123 .\" (These alternatives await a decision about the semantics of O_SEARCH)
124 .\" Search permission is required on this directory
127 .\" was opened with the
131 .\" This file descriptor must have been opened with the
137 in order to specify the current directory.
139 One of the owner or group id's
140 may be left unchanged by specifying it as (uid_t)\-1 or (gid_t)\-1 respectively.
142 .Rv -std chown lchown fchown fchownat
148 will fail and the file will be unchanged if:
151 Search permission is denied for a component of the path prefix.
154 points outside the process's allocated address space.
156 An I/O error occurred while reading from or writing to the file system.
158 Too many symbolic links were encountered in translating the pathname.
159 .It Bq Er ENAMETOOLONG
160 A component of a pathname exceeded
162 characters, or an entire path name exceeded
166 The named file does not exist.
168 A component of the path prefix is not a directory.
170 The effective user ID is not the super-user.
172 The named file resides on a read-only file system.
181 does not specify an absolute path and
185 nor a valid file descriptor open for reading or searching.
188 is not an absolute path and
190 is a file descriptor associated with a non-directory file.
198 does not refer to a valid descriptor.
201 refers to a socket, not a file.
203 An I/O error occurred while reading from or writing to the file system.
205 The effective user ID is not the super-user.
207 The named file resides on a read-only file system.
218 function deviates from the semantics defined in
220 which specifies that, unless the caller is the super-user, both the
221 set-user-id and set-group-id bits on a file shall be cleared, regardless
222 of the file attribute changed.
227 functions, as defined by
229 provide the same semantics.
234 To retain conformance to these standards, compatibility interfaces
257 function call appeared in
264 functions were changed to follow symbolic links in
268 function call appeared in