chown
chown Command
Purpose
Changes the owner or group associated with a file.
Syntax
chown [ -f ] [ -h ] [ -R ] Owner [ :Group ] { File ... | Directory
... }
Description
The chown command changes the owner of the file specified by the File
parameter to the user specified by the Owner parameter. The value
of the Owner parameter can be a user ID or a login name found in the
/etc/passwd file. Optionally, a group can also be specified. The value
of the Group parameter can be a group ID or a group name found in
the /etc/group file.
Only the root user can change the owner of a file. You can change
the group of a file only if you are a root user or if you own the
file. If you own the file but are not a root user, you can change
the group only to a group of which you are a member.
When a symbolic link is encountered and you have not specified the
-h flag, the chown command changes the ownership of the file or directory
pointed to by the link and not the ownership of the link itself.
If you specify the -h flag, the chown command has the opposite effect
and changes the ownership of the link itself and not that of the file
or directory pointed to by the link.
If you specify the -R flag, the chown command recursively descends
the specified directories.
If you specify both the -h flag and the -R flag, the chown command
descends the specified directories recursively, and when a symbolic
link is encountered, the ownership of the link itself is changed and
not that of the file or directory pointed to by the link.
Flags
-f Suppresses all error messages except usage messages.
-h Changes the ownership of an encountered symbolic link and not that
of the file or directory pointed to by the symbolic link.
-R Descends directories recursively, changing the ownership for each
file. When a symbolic link is encountered and the link points to a
directory, the ownership of that directory is changed but the directory
is not further transversed.
Security
Access Control: This program should be installed as a normal user
program in the Trusted Computing Base.
Exit Status
This command returns the following exit values:
0 The command executed successfully and all requested changes were
made.
>0 An error occurred.
Examples
1. To change the owner of the file program.c:
chown jim program.c
The user access permissions for program.c now apply to jim. As the
owner, jim can use the chmod command to permit or deny other users
access to program.c.
2. To change the owner and group of all files in the directory /tmp/src
to owner john and group build:
chown -R john:build /tmp/src
Implementation Specifics
Software Product/Option: Base Operating System/ AIX 3.2 to 4.1 Compatibility
Links
Standards Compliance: OSF/1, OSF Level 3, BSD 4.3, SVID 3, SVID 2,
XPG4, XPG3, POSIX
Files
/usr/bin/chown The chown command
/etc/group File that contains group IDs
/etc/passwd File that contains user IDs
Related Information
The chgrp command, chmod command.
The chown subroutine, fchown subroutine.
The File Ownership and User Groups in AIX Version 4.1 System User's
Guide: Operating System and Devices introduces file ownership and
permissions to access files and directories.
The Security Administration in AIX Version 4.1 System Management Guide:
Operating System and Devices describes system security.
=================================================================
=================================================================
chown, fchown, lchown, chownx, or fchownx Subroutine
Purpose
Changes file ownership.
Library
Standard C Library (libc.a)
Syntax
Syntax for the chown, fchown, and lchown Subroutines:
#include
int chown (Path, Owner, Group)
const char *Path;
uid_t Owner;
gid_t Group;
int fchown (FileDescriptor, Owner, Group)
int FileDescriptor;
uid_t Owner;
gid_t Group;
int lchown (Path, Owner, Group)
const char *fname
uid_t uid
gid_t gid
Syntax for the chownx and fchownx Subroutines:
#include
#include
int chownx (Path, Owner, Group, Flags)
char *Path;
uid_t Owner;
gid_t Group;
int Flags;
int fchownx (FileDescriptor, Owner, Group, Flags)
int FileDescriptor;
uid_t Owner;
gid_t Group;
int Flags;
Description
The chown, chownx, fchown, fchownx, and lchown subroutines set the
file owner and group IDs of the specified file system object. Root
user authority is required to change the owner of a file.
A function lchown function sets the owner ID and group ID of the named
file similarity to chown function except in the case where the named
file is a symbolic link. In this case lchown function changes the
ownership of the symbolic link file itself, while chown function changes
the ownership of the file or directory to which the symbolic link
refers.
Parameters
FileDescriptor Specifies the file descriptor of an open file.
Flags Specifies whether the file owner ID or group ID should be changed.
This parameter is constructed by logically ORing the following values:
T_OWNER_AS_IS Ignores the value specified by the Owner parameter and
leaves the owner ID of the file unaltered.
T_GROUP_AS_IS Ignores the value specified by the Group parameter and
leaves the group ID of the file unaltered.
Group Specifies the new group of the file. If this value is -1, the
group is not changed. (A value of -1 indicates only that the group
is not changed; it does not indicate a group that is not valid. An
owner or group ID cannot be invalid.)
Owner Specifies the new owner of the file. If this value is -1, the
owner is not changed. (A value of -1 indicates only that the group
is not changed; it does not indicate a group that is not valid. An
owner or group ID cannot be invalid.)
Path Specifies the full path name of the file. If Path resolves to
a symbolic link, the ownership of the file or directory pointed to
by the symbolic link is changed.
Return Values
Upon successful completion, the chown, chownx, fchown, fchownx, and
lchown subroutines return a value of 0. If the chown, chownx, fchown,
fchownx, or lchown subroutine is unsuccessful, a value of -1 is returned
and the errno global variable is set to indicate the error.
Error Codes
The chown, chownx, or lchown subroutine is unsuccessful and the owner
and group of a file remain unchanged if one of the following is true:
EACCESS Search permission is denied on a component of the Path parameter.
EDQUOT The new group for the file system object cannot be set because
the group's quota of disk blocks or i-nodes has been exhausted on
the file system.
EFAULT The Path parameter points to a location outside of the allocated
address space of the process.
EINVAL The owner or group ID supplied is not valid.
ELOOP Too many symbolic links were encountered in translating the
Path parameter.
ENAMETOOLONG A component of the Path parameter exceeded 255 characters,
or the entire Path parameter exceeded 1023 characters.
ENOENT A symbolic link was named, but the file to which it refers
does not exist; or a component of the Path parameter does not exist;
or the process has the disallow truncation attribute set; or the Path
parameter is null.
ENOTDIR A component of the path prefix is not a directory.
EPERM The effective user ID does not match the owner of the file,
and the calling process does not have the appropriate privileges.
EROFS The named file resides on a read-only file system.
ESTALE The root or current directory of the process is located in
a virtual file system that has been unmounted.
The fchown or fchownx subroutine is unsuccessful and the file owner
and group remain unchanged if one of the following is true:
EBADF The named file resides on a read-only file system.
EDQUOT The new group for the file system object cannot be set because
the group's quota of disk blocks or i-nodes has been exhausted on
the file system.
EIO An I/O error occurred during the operation.
Security
Access Control: The invoker must have search permission for all components
of the Path parameter.
=================================================================
=================================================================
chown, fchown, lchown, chownx, or fchownx Subroutine
Purpose
Changes file ownership.
Library
Standard C Library (libc.a)
Syntax
Syntax for the chown, fchown, and lchown Subroutines:
#include
int chown (Path, Owner, Group)
const char *Path;
uid_t Owner;
gid_t Group;
int fchown (FileDescriptor, Owner, Group)
int FileDescriptor;
uid_t Owner;
gid_t Group;
int lchown (Path, Owner, Group)
const char *fname
uid_t uid
gid_t gid
Syntax for the chownx and fchownx Subroutines:
#include
#include
int chownx (Path, Owner, Group, Flags)
char *Path;
uid_t Owner;
gid_t Group;
int Flags;
int fchownx (FileDescriptor, Owner, Group, Flags)
int FileDescriptor;
uid_t Owner;
gid_t Group;
int Flags;
Description
The chown, chownx, fchown, fchownx, and lchown subroutines set the
file owner and group IDs of the specified file system object. Root
user authority is required to change the owner of a file.
A function lchown function sets the owner ID and group ID of the named
file similarity to chown function except in the case where the named
file is a symbolic link. In this case lchown function changes the
ownership of the symbolic link file itself, while chown function changes
the ownership of the file or directory to which the symbolic link
refers.
Parameters
FileDescriptor Specifies the file descriptor of an open file.
Flags Specifies whether the file owner ID or group ID should be changed.
This parameter is constructed by logically ORing the following values:
T_OWNER_AS_IS Ignores the value specified by the Owner parameter and
leaves the owner ID of the file unaltered.
T_GROUP_AS_IS Ignores the value specified by the Group parameter and
leaves the group ID of the file unaltered.
Group Specifies the new group of the file. If this value is -1, the
group is not changed. (A value of -1 indicates only that the group
is not changed; it does not indicate a group that is not valid. An
owner or group ID cannot be invalid.)
Owner Specifies the new owner of the file. If this value is -1, the
owner is not changed. (A value of -1 indicates only that the group
is not changed; it does not indicate a group that is not valid. An
owner or group ID cannot be invalid.)
Path Specifies the full path name of the file. If Path resolves to
a symbolic link, the ownership of the file or directory pointed to
by the symbolic link is changed.
Return Values
Upon successful completion, the chown, chownx, fchown, fchownx, and
lchown subroutines return a value of 0. If the chown, chownx, fchown,
fchownx, or lchown subroutine is unsuccessful, a value of -1 is returned
and the errno global variable is set to indicate the error.
Error Codes
The chown, chownx, or lchown subroutine is unsuccessful and the owner
and group of a file remain unchanged if one of the following is true:
EACCESS Search permission is denied on a component of the Path parameter.
EDQUOT The new group for the file system object cannot be set because
the group's quota of disk blocks or i-nodes has been exhausted on
the file system.
EFAULT The Path parameter points to a location outside of the allocated
address space of the process.
EINVAL The owner or group ID supplied is not valid.
ELOOP Too many symbolic links were encountered in translating the
Path parameter.
ENAMETOOLONG A component of the Path parameter exceeded 255 characters,
or the entire Path parameter exceeded 1023 characters.
ENOENT A symbolic link was named, but the file to which it refers
does not exist; or a component of the Path parameter does not exist;
or the process has the disallow truncation attribute set; or the Path
parameter is null.
ENOTDIR A component of the path prefix is not a directory.
EPERM The effective user ID does not match the owner of the file,
and the calling process does not have the appropriate privileges.
EROFS The named file resides on a read-only file system.
ESTALE The root or current directory of the process is located in
a virtual file system that has been unmounted.
The fchown or fchownx subroutine is unsuccessful and the file owner
and group remain unchanged if one of the following is true:
EBADF The named file resides on a read-only file system.
EDQUOT The new group for the file system object cannot be set because
the group's quota of disk blocks or i-nodes has been exhausted on
the file system.
EIO An I/O error occurred during the operation.
Security
Access Control: The invoker must have search permission for all components
of the Path parameter.