Change the owner and user groups of Linux files (Chown and CHGRP)

Source: Internet
Author: User

, using chown CommandChange file ownerin the shell, you can use thechown Commandto change all the files. chown Commandis the abbreviation for change owner (changing owner). It needs to be noted thatThe user must be in the existing system, that is, can only be changed to the document in the/etc/passwd username said talent enough.

chown Commandcan also be used to change the name of the user group directly.

Also, if you want to change the file owner at the same time as all subfolders or files under the folder, add the- r parameter directly.

the basic syntax:Chown[- R]Account namefileOrfolderChown[- R]Account name:User group namefileOrfolder number of references:- R: A continuous change of recursion (recursive), that is, all files and folders under the subfolder are updated to this user group. It is often used in situations where a folder has been changed. Demo Sample 1: [[email protected] home]#Touchtestfile//Create a file from the root user[Email protected] home]#lstestfile–l-rw--w--w-1 root root 0 June 7 19:35 testfile//File owner and owner level are root[Email protected] home]#ChownYangzongdetestfile//Change file owner to Yangzongde[Email protected] home]#lstestfile- L-rw--w--w-1 yangzongde Root 0 June 7 19:35 testfile//View the file owner as Yangzongde. But the group is still root Demo Sample 2:Chown bin Install.logls- L-rw-r--r--1 bin users 68495 June 08:53 Install.logChownRoot:RootInstall.logls-l-rw-r--r--1 root root 68495 June 08:53 Install.logthird, the use chgrp CommandChange the user group to which the file belongsin the shell, you can use thechgrp Commandto change the user group that the file belongs to, which is the abbreviation for change group (changing user groups).

It is important to note that the name of the user group to be changed must exist in the /etc/group , otherwise the error will be displayed.

the basic syntax:chgrp[- R]User group namedirname/filename... number of references:- R: A continuous change of recursion (recursive), that is, all files and folders under the subfolder are updated to this user group. It is often used in situations where a folder has been changed. Demo Sample 3[Email protected] home]#lstestfile- L-rw--w--w-1 yangzongde Root 0 June 7 19:35 testfile//View the file owner as Yangzongde. But the group is root[Email protected] home]#chgrp Yangzongdetestfile//Change the owner group to Yangzongde[Email protected] home]#ls testfile- L-rw--w--w-1 yangzongde yangzongde 0 June 7 19:35 testfile[Email protected] home]#ChownRoot:Roottestfile//Use Chown to change owners and groups at once[Email protected] home]#lstestfile- L-rw--w--w-1 root root 0 June 7 19:35 testfile Demo Sample 4[Email protected] ~]#chgrpUsersInstall.log[Email protected] ~]#ls- L-rw-r--r--1 root users 68495 June 08:53 Install.log Demo Sample 5Change to a /etc/groupinNon-existent user groups [[email protected] ~]#chgrpTesting Install.logchgrp:invalid group name ' testing ' <== error message ~ Could not find this user group name ~

Change the owner and user groups of Linux files (Chown and CHGRP)

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.