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 the file owner. chown Commandis the abbreviation for change owner (changing owner). It is important to note thatThe user must be in an existing system, which can only be changed to a user name that is logged in the/etc/passwd file.. chown Commandmany uses, you can also directly modify the name of the user group. Also, if you want to change the file owner at the same time as all subdirectories or files under the directory, add- Rparameters. Basic Syntax:Chown[- R]Account namefileOrCatalogueChown[- R]Account name:User group namefileOrCatalogue Parameters:- R: A continuous change of recursion (recursive), that is, all files and directories under the subdirectory are updated to this user group. Often used in situations where a directory is changed. Example 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]#ChownYangzongde testfile//Modify file owner to Yangzongde[Email protected] home]#lstestfile- L-rw--w--w-1 yangzongde Root 0 June 7 19:35 testfile//View file owner is Yangzongde, but group is still root Example 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 be /etc/groupor the error will be displayed. Basic Syntax:chgrp[- R]User group namedirname/filename... Parameters:- R: A continuous change of recursion (recursive), that is, all files and directories under the subdirectory are updated to this user group. Often used in situations where a directory is changed. Example 3[Email protected] home]#lstestfile - L-rw--w--w-1 yangzongde Root 0 June 7 19:35 testfile//View file owner is Yangzongde, but group is root[Email protected] home]#chgrp Yangzongdetestfile//Modify the owner group to Yangzongde[Email protected] home]#lstestfile- L-rw--w--w-1 yangzongde yangzongde 0 June 7 19:35 testfile[Email protected] home]#ChownRoot:Roottestfile//Use Chown to modify owners and groups at once[Email protected] home]#lstestfile- L-rw--w--w-1 root root 0 June 7 19:35 testfile Example 4[Email protected] ~]#chgrpUsersInstall.log[Email protected] ~]#ls- L-rw-r--r--1 root users 68495 June 08:53 Install.log Example 5Change to a /etc/groupinNon-existent user groups [[email protected] ~]#chgrpTestingInstall.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)

Related Article

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.