One Linux command per day: Chown Command detailed _linux

Source: Internet
Author: User

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-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 u Sers   0 11-30 08:39 log2016.log
-rw-r--r--1 root users   0 11-30 08:39 log2017.log
[root@localhost test6]#

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 mail mai L 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 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 ro Ot:log2012.log 
[root@localhost test6]# ll
Total 604
---xr--r--1 root users 302108 11-30 08:39 18/>---xr--r--1 root 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 users   0 11-30 08:39 log2016.log
-rw-r--r--1 root users   0 11-30 08:39 log2017.log
[R Oot@localhost test6]#

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-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:m Ail Log2012.log 
[root@localhost test6]# ll
Total 604
---xr--r--1 root users 302108 11-30 08:39 18/>---xr--r--1 root 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 users   0 11-30 08:39 log2016.log
-rw-r--r--1 root users   0 11-30 08:39 Log2017.log

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@localhos The owner of the T test]# chown-r-v root:mail test6 "Test6/log2014.log" has changed to Root:mail "Test6/linklog.log" the owner has changed to Root:mail "test6/ Log2015.log owner has changed to Root:mail "Test6/log2013.log" owner has been changed to Root:mail "Test6/log2012.log" owner 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 ma Il 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 

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.