The Chown of Linux commands

Source: Internet
Author: User

chown Change the file all people and groups

Grammar:

chown [OPTION] [Owner][:[group]] FILE

chown [OPTION]--reference=rfile FILE

Descriptive narrative:

Chown the owner of the user and/or group that changed the specified file.

    • assuming that only the owner (username live in the user ID) is given, after running this statement, only the owner of the selected file is changed, the group of files is unchanged.

Like what:

[Email protected]:~/mycode/test$ ls-l
Total dosage 0

-rw-rw-r--1 Liujl liujl 0 2012-06-20 09:31 mytest.txt

After running Chown:

[Email protected]:~/mycode/test$ sudo chown juanzhang mytest.txt
[sudo] password for LIUJL:
[Email protected]:~/mycode/test$ ls-l
Total dosage 0
-rw-rw-r--1 Juanzhang liujl 0 2012-06-20 09:31 mytest.txt

    • assuming the owner follows the ":" and the group name (or group ID), note that there are no spaces on either side of the ":", and the user and group owner will change after the statement is run , such as:

[Email protected]:~/mycode/test$ ls-l
Total dosage 0

-rw-rw-r--1 Liujl liujl 0 2012-06-20 09:31 mytest.txt

After running Chown:

[Email protected]:~/mycode/test$ sudo chown liujl:liujl mytest.txt
[sudo] password for LIUJL:
[Email protected]:~/mycode/test$ ls-l
Total dosage 0
-rw-rw-r--1 liujl liujl 0 2012-06-20 09:31 mytest.txt

    • Assuming there is only ":", but there is no group name, the system changes the owner of the file and the group in which the owning group resides.

Like what:

[Email protected]:~/mycode/test$ ls-l
Total dosage 0
-rw-rw-r--1 liujl liujl 0 2012-06-20 09:31 mytest.txt

[Email protected]:~/mycode/test$ sudo chown juanzhang:mytest.txt
[sudo] password for LIUJL:
[Email protected]:~/mycode/test$ ls-l
Total dosage 0
-rw-rw-r--1 Juanzhang juanzhang 0 2012-06-20 09:31 mytest.txt

    •   assumes ":" and the group name is given, but the owner ignores that only the group name is altered; In such cases, chown functions are similar to CHGRP functions .

[Email protected]:~/mycode/test$ ls-l
Total dosage 0
-rw-rw-r--1 Juanzhang juanzhang 0 2012-06-20 09:31 mytest.txt
[Email protected]:~/mycode/test$ sudo chown:liujl mytest.txt
[Email protected]:~/mycode/test$ ls-l
Total dosage 0
-rw-rw-r--1 Juanzhang liujl 0 2012-06-20 09:31 mytest.txt

    • Assuming that only ":" is given or the entire operand is empty, the file owner or group name does not change.

           [email protected]:~/mycode/test$ ls-l
           Total usage 0
           -rw-rw-r--1 juanzhang liujl 0 2012-06-20 09:31 mytest.txt
& nbsp;          [email protected]:~/mycode/test$ chown:mytest.txt
           [email  protected]:~/mycode/test$ ls-l
           Total usage 0
          -rw-rw-r--1 Juanzhang LIUJL 0 2012-06-20 09:31 mytest.txt
            The entire operand is empty and an error occurs:

[Email protected]:~/mycode/test$ chown mytest.txt
Chown: The operand is missing after "Mytest.txt"

Number of references:

-r: Continuous changes to the recursive, will be the same subfolder of all files, folders are updated to ask this user group. Pass is often used in situations where a folder is changed.

Application:

The most common use of this command is when we use the MV or CP copy to other people, the owner and group name of these files have not changed, so we need to change them.

Examples:

[Email protected]:/usr$ ls-l|grep mytest2.txt
-rw-r--r--1 root root 0 2012-06-20 13:50 mytest2.txt
[Email protected]:/usr$ sudo mv mytest2.txt/home/liujl/mycode/test/
[Email protected]:~/mycode/test$ ls-l
Total dosage 0
-rw-r--r--1 root root 0 2012-06-20 13:50 mytest2.txt
Now Mytest2.txt has MV to LIUJL users, but when the change is not agreed, from the above sentence can be seen, or belong to root root, this needs to chown.

RICHERG85 column//record their work in the study of a bit, hope one day will become strong//

The Chown of Linux commands

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.