Linux Base command (chown command)

Source: Internet
Author: User
Tags linux

Chown changes the owner of the specified file to the specified user or group, the user can be a user name or a user ID, the group can be a group name or a group ID, and the 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 the file after copying it to another user's directory.

1. Command format:

chown [Options] ... Owner [: [Group]] file ...

2. Command function:

Change the owner and group of files through Chown. You can use the user name and user ID settings when you change the owner of the file or the owning group. Ordinary users cannot change their files to other owners. Its operational permissions are generally administrators.

3. Command parameters:

Necessary parameters:

-C Displays information about the changed part

-F ignores error messages

-H Repair Symbolic link

-R handles all files in the specified directory and its subdirectories

-V Display detailed processing information

-deference to the point of the symbolic link, not to the linked file itself

Select parameters:

--reference=< directory or File > The specified directory/file as a reference, the operation of the file/directory set to reference files/directories of the same owners and groups

--from=< Current User: Current group > change only if the current user and group are the same as the specified user and group

--HELP Display Help information

--version Display version Information

4. Use instance:

Example 1: Changing Owners and groups

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 1 1-30 08:39 Log2012.log   
-rw-r--r--1 root users 11-30 11-30 08:39 log2013.log-rw-r--r--   
1 root users      0  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   
Log 2012.log    
[root@localhost test6]# ll   
---xr--r--1 root users 302108 11-30 08:39 linklog.log   
---xr--r--1 ma Il mail  302108 11-30 08:39 log2012.log   
-rw-r--r--1 root users     11-30 08:39   
log2013.log 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]#

Description

Example 2: Changing file owners and groups

Command:

Chown Root:log2012.log

Output:

[Root@localhost test6]# 

ll   
Total 604
---xr--r--1 root users 302108 11-30 08:39   
---linklog.log 1 mai  L Mail  302108 11-30 08:39 log2012.log   
-rw-r--r--1 root users     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 US ERs      0 11-30 08:39 log2016.log   
-rw-r--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 08:3 9 Linklog.log   
---xr--r--1 root root  302108 11-30 08:39 log2012.log   
-rw-r--r--1 root users     61 11-30 0 8: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:  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]#

Description

Example 3: Changing the file group

Command:

Chown:mail Log2012.log

Output:

[Root@localhost test6]# ll   
Total 604
---xr--r--1 root users 302108 11-30 08:39 linklog.log   
---xr--r--1 root roo T  302108 11-30 08:39 log2012.log   
-rw-r--r--1 root users 11-30     08:39 log2013.log   
1 root user S      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]# cho Wn:mail log2012.log    
[root@localhost test6]# ll   
Total 604
---xr--r--1 root users 302108 11-30 08:39 OG   
---xr--r--1 root mail  302108 11-30 08:39 log2012.log   
-rw-r--r--1 root users 11-30     08:39 log201 3.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.lo G

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:

 [root@localhost test]# ll drwxr-xr-x 2 root users 4096 11-30 08:39 Test6] [root@localhost test]# chown-r-V  The owner of the Root:mail Test6 "Test6/log2014.log" has changed to Root:mail "Test6/linklog.log" has changed to Root:mail "Test6/log2015.log" The owner of the Root:mail "Test6/log2013.log" has been changed to the owner of the Root:mail "Test6/log2012.log" has been reserved for Root:mail "test6/log2017. Log "owner has changed to Root:mail" Test6/log2016.log "owner has changed to Root:mail" Test6 "has changed to Root:mail [Root@localhost test]#   
ll Drwxr-xr-x 2 root mail 4096 11-30 08:39 test6 [root@localhost test]# cd Test6 [root@localhost 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 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 

See a full set of tutorials: http://www.bianceng.cn/OS/Linux/201301/35075.htm

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.