Linux command chown

Source: Internet
Author: User
Linux command to change the file owner and group syntax: www.2cto. comchown [OPTION] [OWNER] [: [GROUP] FILEchown [OPTION] -- referenceRFILEFILE description: chown changes the user and/or GROUP of the specified file... linux command chown change file owner and GROUP syntax: www.2cto.com chown [OPTION] [OWNER] [: [GROUP] FILE chown [OPTION] -- reference = rfile file description: chown changes the user of the specified file and/or the owner of the group. If only the owner is specified (the user name lives in the user ID), after this statement is executed, only the owner of the selected file is changed, and the file group is not changed. For example: liujl @ liujl-Rev-1-0 :~ /Mycode/TEST $ ls-l total usage 0-rw-r -- 1 liujl 0 2012-06-20 mytest.txt after chown execution: liujl @ liujl-Rev-1-0 :~ /Mycode/TEST $ sudo chown juanzhang mytest.txt [sudo] password for liujl: www.2cto.com liujl @ liujl-Rev-1-0 :~ /Mycode/TEST $ ls-l total usage 0-rw-r -- 1 juanzhang liujl 0 2012-06-20 mytest.txt if the owner follows ": "and group name (or group ID), note that there is no space on both sides of the": ", after this statement is executed, the user and the group owner will change, for example: liujl @ liujl-Rev-1-0: ~ /Mycode/TEST $ ls-l total usage 0-rw-r -- 1 liujl 0 2012-06-20 mytest.txt after chown execution: liujl @ liujl-Rev-1-0 :~ /Mycode/TEST $ sudo chown liujl: liujl mytest.txt [sudo] password for liujl: liujl @ liujl-Rev-1-0 :~ /Mycode/TEST $ ls-l total usage 0-rw-r -- 1 liujl 0 2012-06-20 mytest.txt if there is only ":", but there is no group name, the system changes the owner of the file and the Group of the owner group. For example: liujl @ liujl-Rev-1-0 :~ /Mycode/TEST $ ls-l total usage 0-rw-r -- 1 liujl 0 2012-06-20 mytest.txt liujl @ liujl-Rev-1-0 :~ /Mycode/TEST $ sudo chown juanzhang: mytest.txt [sudo] password for liujl: liujl @ liujl-Rev-1-0 :~ /Mycode/TEST $ ls-l total usage 0-rw-r -- 1 juanzhang 0 2012-06-20 09:31 mytest.txt if ":" and group name are given, but the owner ignores it, only the group name is modified. in this case, chown functions similar to chgrp. Liujl @ liujl-Rev-1-0 :~ /Mycode/TEST $ ls-l total usage 0 www.2cto.com-rw-r -- 1 juanzhang 0 2012-06-20 mytest.txt iujl @ liujl-Rev-1-0 :~ /Mycode/TEST $ sudo chown: liujl mytest.txt liujl @ liujl-Rev-1-0 :~ /Mycode/TEST $ ls-l total usage 0-rw-r -- 1 juanzhang liujl 0 2012-06-20 09:31 mytest.txt if only ":" is specified or the entire operand is null, the file owner or group name will not change. Liujl @ liujl-Rev-1-0 :~ /Mycode/TEST $ ls-l total usage 0-rw-r -- 1 juanzhang liujl 0 2012-06-20 mytest.txt liujl @ liujl-Rev-1-0 :~ /Mycode/TEST $ chown: mytest.txt liujl @ liujl-Rev-1-0 :~ /Mycode/TEST $ ls-l total usage 0-rw-r -- 1 juanzhang liujl 0 2012-06-20 09:31 mytest.txt the entire operand is empty, will report the error: liujl @ liujl-Rev-1-0 :~ /Mycode/TEST $ chown mytest.txt chown: "mytest.txt" without the operand parameter:-R: for recursive continuous changes, this user group is updated to all files and directories in the same subdirectory. It is usually used to change a directory. Application scenario: The most common use of this command is that when we use mv or cp to copy these files to others, the owner and group names of these files are not changed, so we need to modify them. Www.2cto.com example: liujl @ liujl-Rev-1-0:/usr $ ls-l | grep mytest2.txt-rw-r -- 1 root 0 2012-06-20 mytest2.txt liujl @ liujl-Rev-1-0: /usr $ sudo mv mytest2.txt/home/liujl/mycode/TEST/liujl @ liujl-Rev-1-0 :~ /Mycode/TEST $ ls-l total usage 0-rw-r -- 1 root 0 2012-06-20 mytest2.txt now mytest2.txt has been mv to the liujl user, however, it is not allowed to be modified. as can be seen from the above sentence, it still belongs to the root, which requires chown. Author: richerg85

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.