Linux Chown (Change the owner of the specified file to the specified user or group)

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:

 Necessary parameters:

-C Displays information about the changed parts

-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, not the linked file itself

  Select parameters:

--reference=< directory or File > Specify the directory/file as the reference, the operation of the file/directory to the reference file/directory of the 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 Help information

--version displaying version information

  4. Usage examples:

  Example 1: Changing Owners and groups

Command:

Chown Mail:mail Log2012.log

  Output: 

650) this.width= 650, "src="/e/u261/themes/default/images/spacer.gif "alt=" Copy Code "style=" Background:url ("/e/u261/lang/zh-cn/images/ Localimage.png ") no-repeat center;border:1px solid #ddd;/>

[[Email protected] 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[[email protected] test6]# chown mail:mail  LOG2012.LOG&NBSP;[[EMAIL&NBSP;PROTECTED]&NBSP;TEST6]#&NBSP;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[[email protected] test6]#

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "alt=" Copy Code "style=" Background:url ("/e/u261/ Lang/zh-cn/images/localimage.png ") no-repeat center;border:1px solid #ddd;"/>

Description

  Example 2: Changing file owners and groups

Command:

Chown Root:log2012.log

  Output:    

650) this.width= 650, "src="/e/u261/themes/default/images/spacer.gif "alt=" Copy Code "style=" Background:url ("/e/u261/lang/zh-cn/images/ Localimage.png ") no-repeat center;border:1px solid #ddd;/>

[[Email protected] test6]# ll Total  604---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[[email protected] test6]# chown root: &NBSP;LOG2012.LOG&NBSP;[[EMAIL&NBSP;PROTECTED]&NBSP;TEST6]#&NBSP;LL Total  604---xr--r-- 1 root  users 302108 11-30 08:39 linklog.log---xr--r-- 1 root root  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[[email protected] test6]#

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "alt=" Copy Code "style=" Background:url ("/e/u261/ Lang/zh-cn/images/localimage.png ") no-repeat center;border:1px solid #ddd;"/>

  Description

  Example 3: Changing file groups

Command:

Chown:mail Log2012.log

  Output:  

650) this.width= 650, "src="/e/u261/themes/default/images/spacer.gif "alt=" Copy Code "style=" Background:url ("/e/u261/lang/zh-cn/images/ Localimage.png ") no-repeat center;border:1px solid #ddd;/>

[[Email protected] test6]# ll Total  604---xr--r-- 1 root users 302108  11-30 08:39 linklog.log---xr--r-- 1 root root  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[[email protected] test6]# chown :mail &NBSP;LOG2012.LOG&NBSP;[[EMAIL&NBSP;PROTECTED]&NBSP;TEST6]#&NBSP;LL Total  604---xr--r-- 1 root  users 302108 11-30 08:39 linklog.log---xr--r-- 1 root 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

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "alt=" Copy Code "style=" Background:url ("/e/u261/ Lang/zh-cn/images/localimage.png ") no-repeat center;border:1px solid #ddd;"/>

  Description

  Example 4: Changing the owner and group of all files in the specified directory and its subdirectories

Command:

Chown-r-V Root:mail test6

  Output:  

650) this.width= 650, "src="/e/u261/themes/default/images/spacer.gif "alt=" Copy Code "style=" Background:url ("/e/u261/lang/zh-cn/images/ Localimage.png ") no-repeat center;border:1px solid #ddd;/>

[[email protected] test]# lldrwxr-xr-x 2 root users   4096  11-30 08:39 test6[[email protected] test]# chown -r -v root:mail  Test6 "Test6/log2014.log"   owner has changed to  root:mail "Test6/linklog.log"   owner has changed to  root:mail "test6/ Log2015.log "  owner changed to  root:mail" Test6/log2013.log "  owner has changed to  root:mail" Test6/log2012.log " The owner of   has been reserved for  root:mail "Test6/log2017.log"   the owner has changed to  root:mail "Test6/log2016.log"   the owner has changed to  root:mail the owner of the "Test6"   has changed to  root:mail[[email protected] test]# lldrwxr-xr-x  2 root mail   4096 11-30 08:39 test6[[email protected] test] # cd test6[[email protected] test6]# ll Total  604---xr--r-- 1 root  Mail 302108 11-30 08:39 linklog.log---xr--r-- 1 root mail 302108  11-30 08:39 log2012.log-rw-r--r-- 1 root mail     61 11-30 08:39  log2013.log-rw-r--r-- 1 root mail      0 11-30  08:39 log2014.log-rw-r--r-- 1 root mail      0 11-30  08:39 log2015.log-rw-r--r-- 1 root mail      0  11-30 08:39 log2016.log-rw-r--r-- 1 root mail      0  11-30 08:39 log2017.log

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "alt=" Copy Code "style=" Background:url ("/e/u261/ Lang/zh-cn/images/localimage.png ") no-repeat center;border:1px solid #ddd;"/>




This article is from "Linux rookie" blog, please be sure to keep this source http://490617581.blog.51cto.com/11186315/1757773

Linux Chown (Change the owner of the specified file to the specified user or group)

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.