[One Linux Command every day] 09. Usage of chown in Linux

Source: Internet
Author: User


Chown can change the owner or group of a file. The file is a list of files separated by spaces to change permissions. Wildcards are supported.

The system administrator often uses the CHOWN command to grant the user the permission to use the file after copying the file to another user's directory.


Command Format:

Chown [-F] [-H] [-R] owner [: Group] {file... | directory ...}
Chown-R [-F] [-H |-L |-p] owner [: Group]
{File... | directory... }

Command description:


ChownCommandFileThe owner of the file specified by the parameter is changedOwnerThe user specified by the parameter.
OwnerThe parameter value can be/Etc/passwdUser ID or login name found in the file. You can also select a group.
GroupThe parameter value can be/Etc/groupThe Group ID or group name found in the file.

Note:

1. Only the root user can change the file owner. You can change the file group only when you are a root user or have the file.

2. If you have a file but are not a root user, you can only change the group to a group where you are a member.

3. Although the-h,-l, and-P flags are mutually exclusive, specifying more than one mark is not considered as an error.

Command Parameters 1. required parameters:

-C: display the changed information.
-F ignore error messages
-H: fixed the symbolic link.
-R processes the specified directory and all files in its subdirectories.
-V: displays detailed processing information.
-Deference acts on the point of the symbolic link, rather than the link file itself.

2. Select parameters:

-- Reference = <directory or File> specifies the directory/file as a reference, and sets the operated file/directory to the same owner and group of the reference file/directory.
-- From = <Current User: current group> only when the current user and group are the same as the specified user and group
-- Help: displays help information.
-- Version: displays version information.

Command example: Change the file owner

Example 1: Change the owner of the testchown.txt File

bixiaopeng@ubuntu:~$ chown bixiaopeng testchown.txt bixiaopeng@ubuntu:~$ ls -al testchown.txt-rw-rw-r-- 1 bixiaopeng bixiaopeng 22  8��� 14 08:08 testchown.txt

Change the directory owner


Example 2: Change the owner and group of all files in the testfile folder to user bixiaopeng and group sambashare

# First, check the users and groups of testfile bixiaopeng @ Ubuntu :~ $ LS-Al testfile-RW-r -- 1 bixiaopeng 536870912 6 �� 16 testfile # Change bixiaopeng @ Ubuntu :~ $ Chown-r bixiaopeng: sambashare testfilebixiaopeng @ Ubuntu :~ $ LS-Al testfile-RW-r -- 1 bixiaopeng sambashare 536870912 6 �� 16 testfile # change the group back to bixiaopeng @ Ubuntu :~ $ Chown-r bixiaopeng: bixiaopeng testfilebixiaopeng @ Ubuntu :~ $ LS-Al testfile-RW-r -- 1 bixiaopeng 536870912 6 �� 16 testfile


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.