First, use
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 name fileOrCatalogue
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]#ChownYangzongdetestfile//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.logSecond, 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 ~
Owner and user group of modified files under Linux