Linux Command Learning Note (chown): command

Source: Internet
Author: User

Chown The owner of the specified file to the specified user or group, the user can be either a user name or a user ID; a group can be a group name or a group ID; a file is a space-separated list of files to change permissions, and wildcard characters are supported.  System administrators often use the Chown command to give users permission to use a file after copying it to another user's directory. 1. Command format:Chown[Options] ... Owner [: [Group]] file ...2. Command function: Change the file owner and group by Chown. You can use the user name and user identification number settings when you change the owner or group of the file. Ordinary users cannot change their files to other owners.  Its operation permissions are generally administrators. 3. Command parameters: Required Parameters:-c Display information for the changed section-F Ignore Error messages-h fix Symbolic link-R handles all files in the specified directory and its subdirectories-v displays detailed processing information-deference acts on the point of a symbolic link, rather than the link file itself, select parameters:--reference=< directory or File > Specify the directory/file as a reference, the operation of the file/directory set as a reference file/Directory same owner and group--from=< Current User: Current group >changes only if the current user and group are the same as the specified user and group--Help Display assistance information--version displays release information4. Use instance: Instance 1: Change owner and Group commands:Chownmail:mail log2012.log output: [[email protected] test6]# ll---xr--r--1Root Users302108  One- -  ,: theLinklog.log---xr--r--1Root Users302108  One- -  ,: theLog2012.log-rw-r--r--1Root Users A  One- -  ,: theLog2013.log-rw-r--r--1Root Users0  One- -  ,: theLog2014.log-rw-r--r--1Root Users0  One- -  ,: theLog2015.log-rw-r--r--1Root Users0  One- -  ,: theLog2016.log-rw-r--r--1Root Users0  One- -  ,: theLog2017.log[[email protected] test6]#Chownmail:mail Log2012.log[[email protected] test6]# ll---xr--r--1Root Users302108  One- -  ,: theLinklog.log---xr--r--1Mail Mail302108  One- -  ,: theLog2012.log-rw-r--r--1Root Users A  One- -  ,: theLog2013.log-rw-r--r--1Root Users0  One- -  ,: theLog2014.log-rw-r--r--1Root Users0  One- -  ,: theLog2015.log-rw-r--r--1Root Users0  One- -  ,: theLog2016.log-rw-r--r--1Root Users0  One- -  ,: theLog2017.log[[email Protected] test6]# Description: Example 2: Changing file owner and Group commands:Chownroot:log2012.log output: [[email protected] test6]# ll Total604---xr--r--1Root Users302108  One- -  ,: theLinklog.log---xr--r--1Mail Mail302108  One- -  ,: theLog2012.log-rw-r--r--1Root Users A  One- -  ,: theLog2013.log-rw-r--r--1Root Users0  One- -  ,: theLog2014.log-rw-r--r--1Root Users0  One- -  ,: theLog2015.log-rw-r--r--1Root Users0  One- -  ,: theLog2016.log-rw-r--r--1Root Users0  One- -  ,: theLog2017.log[[email protected] test6]#ChownRoot:log2012.log[[email protected] test6]# ll Total604---xr--r--1Root Users302108  One- -  ,: theLinklog.log---xr--r--1Root root302108  One- -  ,: theLog2012.log-rw-r--r--1Root Users A  One- -  ,: theLog2013.log-rw-r--r--1Root Users0  One- -  ,: theLog2014.log-rw-r--r--1Root Users0  One- -  ,: theLog2015.log-rw-r--r--1Root Users0  One- -  ,: theLog2016.log-rw-r--r--1Root Users0  One- -  ,: theLog2017.log[[email Protected] test6]# Description: Instance 3: Change the file Group command:Chown: Mail log2012.log output: [[email protected] test6]# ll Total604---xr--r--1Root Users302108  One- -  ,: theLinklog.log---xr--r--1Root root302108  One- -  ,: theLog2012.log-rw-r--r--1Root Users A  One- -  ,: theLog2013.log-rw-r--r--1Root Users0  One- -  ,: theLog2014.log-rw-r--r--1Root Users0  One- -  ,: theLog2015.log-rw-r--r--1Root Users0  One- -  ,: theLog2016.log-rw-r--r--1Root Users0  One- -  ,: theLog2017.log[[email protected] test6]#Chown: Mail Log2012.log[[email protected] test6]# ll Total604---xr--r--1Root Users302108  One- -  ,: theLinklog.log---xr--r--1Root Mail302108  One- -  ,: theLog2012.log-rw-r--r--1Root Users A  One- -  ,: theLog2013.log-rw-r--r--1Root Users0  One- -  ,: theLog2014.log-rw-r--r--1Root Users0  One- -  ,: theLog2015.log-rw-r--r--1Root Users0  One- -  ,: theLog2016.log-rw-r--r--1Root Users0  One- -  ,: theLog2017.log Description: Instance 4: Change owner and group commands for all files under the specified directory and its subdirectories:Chown-R-v root:mail test6 output: [[email protected] test]# LLDRWXR-xr-x2Root Users4096  One- -  ,: theTest6[[email protected] test]#Chown-R-v root:mail test6 "Test6/Log2014.log "owner changed to Root:mail" Test6/Linklog.log "owner changed to Root:mail" Test6/Log2015.log "owner changed to Root:mail" Test6/Log2013.log "owner changed to Root:mail" Test6/The owner of Log2012.log "has been reserved for root:mail" Test6/Log2017.log "owner changed to Root:mail" Test6/Log2016.log "The owner has changed to Root:mail" Test6 "the owner has changed to Root:mail[[email protected] test]# lldrwxr-xr-x2Root Mail4096  One- -  ,: theTest6[[email protected] test]# CD Test6[[email protected] test6]# ll Total604---xr--r--1Root Mail302108  One- -  ,: theLinklog.log---xr--r--1Root Mail302108  One- -  ,: theLog2012.log-rw-r--r--1Root Mail A  One- -  ,: theLog2013.log-rw-r--r--1Root Mail0  One- -  ,: theLog2014.log-rw-r--r--1Root Mail0  One- -  ,: theLog2015.log-rw-r--r--1Root Mail0  One- -  ,: theLog2016.log-rw-r--r--1Root Mail0  One- -  ,: theLog2017.log

Linux Command Learning Note (chown): command

Related Article

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.