Purpose
Syntax
chown [ -f ] [ -h ] [ -R ] Owner [ :Group ] { File ... | Directory ... }chown -R [ -f ] [ -H | -L | -P ] Owner [ :Group ] { File ... | Directory ... }
Description
The chown command changes the
owner of the file or directory specified by the File or Directory parameter to the user specified by the Owner parameter. The value of the Owner parameter
can be a user name from the user database or a numeric user ID. Optionally,
a group can also be specified. The value of the Group parameter
can be a group name from the group database or a numeric group ID.
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.
Although the -H, -L and -P flags are mutually exclusive, specifying more than one
is not considered an error. The last flag specified determines the behavior
that the command will exhibit.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
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
- 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. - 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
No comments:
Post a Comment