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