One Linux Command every day (30): CHOWN command

Source: Internet
Author: User

Chown changes the owner of a specified file to a specified user or group. The user can be the user name or user ID, and the group can be the group name or group ID; files are separated by spaces to change the permission list. 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.

  1. Command Format:

Chown [Option]... [owner] [: [group] file...

  2. command functions:

Use chown to change the owner and group of a file. When changing the file owner or group, you can use the user name and user ID settings. Normal users cannot change their files to other owners. The operation permission is generally administrator.

 3. command parameters:

 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.

  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.

  4. Example:

  Instance 1: change owner and group

Command:

Chown mail: Mail log2012.log

  Output: 

[root@localhost test6]# ll---xr--r-- 1 root users 302108 11-30 08:39 linklog.log---xr--r-- 1 root users 302108 11-30 08:39 log2012.log-rw-r--r-- 1 root users     61 11-30 08:39 log2013.log-rw-r--r-- 1 root users      0 11-30 08:39 log2014.log-rw-r--r-- 1 root users      0 11-30 08:39 log2015.log-rw-r--r-- 1 root users      0 11-30 08:39 log2016.log-rw-r--r-- 1 root users      0 11-30 08:39 log2017.log[root@localhost test6]# chown mail:mail log2012.log [root@localhost test6]# ll---xr--r-- 1 root users 302108 11-30 08:39 linklog.log---xr--r-- 1 mail mail  302108 11-30 08:39 log2012.log-rw-r--r-- 1 root users     61 11-30 08:39 log2013.log-rw-r--r-- 1 root users      0 11-30 08:39 log2014.log-rw-r--r-- 1 root users      0 11-30 08:39 log2015.log-rw-r--r-- 1 root users      0 11-30 08:39 log2016.log-rw-r--r-- 1 root users      0 11-30 08:39 log2017.log[root@localhost test6]#

Note:

  Instance 2: Change the file owner and group

Command:

Chown root: log2012.log

  Output:    

[Root @ localhost test6] # ll total 604 --- XR -- r -- 1 root users 302108 11-30 linklog. log --- XR -- r -- 1 mail 302108 11-30 08:39 log2012.log-RW-r -- 1 root users 61 11-30 08:39 log2013.log-RW-r -- 1 Root users 0 11-30 08:39 log2014.log-RW-r -- 1 root users 0 11-30 08:39 log2015.log-RW-r -- 1 root users 0 11-30 08:39 log2016.log- RW-r -- 1 root users 0 11-30 08:39 log2017.log [root @ localhost test6] # chown root: log2012.log [root @ localhost test6] # ll total 604 --- XR -- r -- 1 root users 302108 11-30 linklog. log --- XR -- r -- 1 Root 302108 11-30 08:39 log2012.log-RW-r -- 1 root users 61 11-30 08:39 log2013.log-RW-r -- 1 Root users 0 11-30 08:39 log2014.log-RW-r -- 1 root users 0 11-30 08:39 log2015.log-RW-r -- 1 root users 0 11-30 08:39 log2016.log- RW-r -- 1 root users 0 11-30 08:39 log2017.log [root @ localhost test6] #

  Note:

  Instance 3: Change the file group

Command:

Chown: Mail log2012.log

  Output:  

[Root @ localhost test6] # ll total 604 --- XR -- r -- 1 root users 302108 11-30 linklog. log --- XR -- r -- 1 Root 302108 11-30 08:39 log2012.log-RW-r -- 1 root users 61 11-30 08:39 log2013.log-RW-r -- 1 Root users 0 11-30 08:39 log2014.log-RW-r -- 1 root users 0 11-30 08:39 log2015.log-RW-r -- 1 root users 0 11-30 08:39 log2016.log- RW-r -- 1 root users 0 11-30 08:39 log2017.log [root @ localhost test6] # chown: mail log2012.log [root @ localhost test6] # ll total 604 --- XR -- r -- 1 root users 302108 11-30 linklog. log --- XR -- r -- 1 root mail 302108 11-30 log2012.log-RW-r -- 1 root users 61 11-30 08:39 log2013.log-RW-r -- 1 Root users 0 11-30 08:39 log2014.log-RW-r -- 1 root users 0 11-30 08:39 log2015.log-RW-r -- 1 root users 0 11-30 08:39 log2016.log- RW-r -- 1 root users 0 11-30 08:39 log2017.log

  Note:

  Example 4: Change the owner and group of all files in the specified directory and Its subdirectories

Command:

Chown-r-V root: Mail test6

  Output:  

[Root @ localhost test] # lldrwxr-XR-x 2 root users 4096 11-30 test6 [root @ localhost test] # chown-r-V root: the owner of mail test6 "test6/log2014.log" has been changed to root: mail "test6/linklog. the owner of log has changed to root: mail "test6/log2015.log" and has changed to root: mail "test6/log2013.log: the owner of mail "test6/log2012.log" has been reserved as root: The owner of mail "test6/log2017.log" has been changed to root: The owner of mail "test6/log2016.log" has been changed to root: the owner of mail "test6" has been changed to root: mail [root @ localhost test] # lldrwxr-XR-x 2 root mail 4096 11-30 test6 [root @ localhost test] # cd test6 [root @ localhost test6] # ll total 604 --- XR -- r -- 1 root mail 302108 11-30 linklog. log --- XR -- r -- 1 root mail 302108 11-30 log2012.log-RW-r -- 1 root mail 61 11-30 08:39 log2013.log-RW-r -- 1 Root mail 0 11-30 08:39 log2014.log-RW-r -- 1 root mail 0 11-30 08:39 log2015.log-RW-r -- 1 root mail 0 11-30 08:39 log2016.log- RW-r -- 1 root mail 0 11-30 08:39 log2017.log

  Note:

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.