chown
[crifan@localhost ~]$ su
Password:
[root@localhost crifan]# chown -Rf crifan linux_kernel/
From Wikipedia, the free encyclopedia
Jump to: navigation, search
This article or section includes a list of references or external links, but its sources remain unclear because it lacks in-text citations. You can improve this article by introducing more precise citations. |
The chown command is used on Unix-like systems to change the owner of a file. In most implementations, it can only be executed by the Superuser. Unprivileged (regular) users who wish to change the group of a file that they own may use chgrp.
Contents[hide] |
[edit] Usage
The general syntax for the chown command is:
chown [-hHLPR] [[<em>user</em>]][:<em>group</em>] <em>target1</em> [[<em>target2</em> ..]]
- The optional user parameter indicates the new user who should take ownership of the targets.
- The optional group parameter (which must be prefixed with a colon, :) indicates the group with which the targets should be associated.
- The target parameters indicate the files or directories for which the user and/or group will be changed.
[edit] Options
- -h
- If the system supports user IDs for symbolic links, for each file operand that names a file of type symbolic link, chown shall attempt to set the user ID of the symbolic link. If the system supports group IDs for symbolic links, and a group ID was specified, for each file operand that names a file of type symbolic link, chown shall attempt to set the group ID of the symbolic link. If the system does not support user or group IDs for symbolic links, for each file operand that names a file of type symbolic link, chown shall do nothing more with the current file and shall go on to any remaining files.
- -H
- If the -R option is specified and a symbolic link referencing a file of type directory is specified on the command line, chown shall change the user ID (and group ID, if specified) of the directory referenced by the symbolic link and all files in the file hierarchy below it.
- -L
- If the -R option is specified and a symbolic link referencing a file of type directory is specified on the command line or encountered during the traversal of a file hierarchy, chown shall change the user ID (and group ID, if specified) of the directory referenced by the symbolic link and all files in the file hierarchy below it.
- -P
- If the -R option is specified and a symbolic link is specified on the command line or encountered during the traversal of a file hierarchy, chown shall change the owner ID (and group ID, if specified) of the symbolic link if the system supports this operation. The chown utility shall not follow the symbolic link to any other part of the file hierarchy.
- -R
- Recursively change file user and group IDs. For each file operand that names a directory, chown shall change the user ID (and group ID, if specified) of the directory and all files in the file hierarchy below it. Unless a -H, -L, or -P option is specified, it is unspecified which of these options will be used as the default.
[edit] Environment Variables
The following environment variables shall affect the execution of chown:
- LANG
- Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of IEEE Std 1003.1-2001, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.)
- LC_ALL
- If set to a non-empty string value, override the values of all the other internationalization variables.
- LC CTYPE
- Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments).
- LC_MESSAGES
- Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
- NLSPATH
- [XSI] [Option Start] Determine the location of message catalogs for the processing of LC_MESSAGES . [Option End]
[edit] Footnotes
- One of either user or group must be specified. The chown command will not execute properly without at least one of those parameters.
- The user and group parameters can be either symbolic names or identifiers (i.e. a User ID or Group ID).
[edit] Usage examples
- Note, these commands must be run as root, and should be executed via sudo
<font color="#ff0000"><strong># sudo chown root /var/run/httpd.pid</strong> </font>
- Change the owner of /var/run/httpd.pid to ‘root’ (the standard name for the Superuser).
<font color="#ff0000"><strong># sudo chown nobody:nobody /tmp /var/tmp</strong> </font>
- Change the owner of /tmp and /var/tmp to ‘nobody’ (not a good idea)
- Change the group associated with the same targets to the group ‘nobody’ (conventionally the ‘nobody’ user’s group)
<font color="#ff0000"><strong># sudo chown :512 /home</strong> </font>
- Change the group identifier of /home to 512 (regardless of whether a group name is associated with the identifier 512 or not).
<font color="#ff0000"><strong># sudo chown -R us base</strong> </font>
- Change the ownership of base to the user us and make it recursive (-R)