Linux modifies the file owner and the group in which the file resides

Source: Internet
Author: User

CHGRP User name File name-R

Chown User name File name-R

-r = All files in the recursive directory

The above section has been verified

First, modify the file belongs to the group--chgrpModifying a file belongs to a group the simple-CHGRP command is the abbreviation for Change group (which we can use to memorize commands)Syntax: chgrp Group file name/directory Example:[Email protected] ~]# Groupadd Groupa
[Email protected] ~]# Groupadd GROUPB[[email protected] ~] #useradd-G groupazgz[email protected] ~]# Su-zgz[email protected] ~]$ Touch Filea[email protected] ~]$ Touch Fileb[email protected] ~]$ ls-l
Total 8
-rw-r--r--1 zgz groupa 0 Sep 05:48filea
-rw-r--r--1 zgz groupa 0 Sep 05:50fileb         --
[[email protected] zgz]# chgrp Groupbfilea --Change the group Filea belong to
[Email protected] zgz]# ls-l
Total 8
-rw-r--r--1 zgz groupb 0 Sep 05:48filea
-rw-r--r--1 zgz groupa 0 Sep 05:50fileb Second, modify the file owner--chownModify the order of the group to make CHGRP, that is, change group, then modify the file owner's command is naturally chown, that is, Changeowner. Chown features many functions, not only to change the file owner, but also to modify the file group. You can use the-r parameter if you need to change the owner of all the files in a directory. The syntax is as follows: Chown[-r] Account name File/directory Chown [-r] Account name : cluster File/directory Example: [email protected] zgz]# ls-l
Total 20
-rw-r--r--1 ZGZGROUPB 0 Sep26 05:48 Filea
-rw-r--r--1 Zgzgroupa 3 Sep26 05:59 Fileb
Drwxr-xr-x 2 zgz groupa 4096 Sep 06:07zgzdir
[[email protected] zgz]# chown myy Fileb --Change Fileb owner to Myy
[Email protected] zgz]# ls-l
Total 20
-rw-r--r--1 ZGZGROUPB 0 Sep26 05:48 Filea
-rw-r--r--1 Myygroupa 3 Sep26 05:59 Fileb
Drwxr-xr-x 2 zgz groupa 4096 Sep 06:07zgzdir
[email protected] zgz]# chown Myy:groupa Filea -Modify the Filea owner to Myy, and
[[Email protected]zgz]# ls-lwhenModify the group to Groupa
Total 20
-rw-r--r--1 Myygroupa 0 Sep26 05:48 Filea
-rw-r--r--1 Myygroupa 3 Sep26 05:59 Fileb
Drwxr-xr-x 2 zgz groupa 4096 Sep 06:07zgzdir
[[email protected] zgz]# chown-r myy zgzdir Simultaneously change all file owners under it
Total 20
-rw-r--r--1 Myygroupa 0 Sep26 05:48 Filea
-rw-r--r--1 Myygroupa 3 Sep26 05:59 Fileb
Drwxr-xr-x 2 myy groupa 4096 Sep 06:07zgzdir
[Email protected] zgz]# CD zgzdir/
[Email protected] zgzdir]# ls-l
Total 8
-rw-r--r--1 myy groupa 0 Sep 06:07filec
-rw-r--r--1 myy groupa 0 Sep 06:07filed
   Third, change the file permissions--chmod 1. Use numbers to change file permissionsWe already know. -rw-r--r--means that Linux assigns a fixed number to each permission: r:4 (Read access)w:2 (Write permission)x:1 (Execute permissions)When we add these numbers together, we get the permission values for each group, for example-rw-r--r--1 myy groupa 0 Sep26 06:07 filedFirst Group (user): rw-= 4+2+0 = 6Group II: r--= 4+0+0 =4Third Group (others): r--= 4+0+0 =4then 644 is the numeric representation value of the Fileb permission. if we want to change the permissions of a certain file, we first need to convert the permissions into a combination of numbers, for example, we want to-rwxrw-r--, then we should get the number combination: [4+2+1][4+2+0][4+0+0]=764, and then with chmod command to modifychmod Syntax: chmodxyz files/directories Example:[Email protected] zgzdir]# ls-l
Total 8
-rw-r--r--1 myy groupa 0 Sep 06:07filec
-rw-r--r--1 myy groupa 0 Sep 06:07filed
[[email protected] zgzdir]# chmod 777 Filec--Change Filec permissions to 777
[Email protected] zgzdir]# ls-l
Total 8
-RWXRWXRWX 1 myy groupa 0 Sep 06:07filec
-rw-r--r--1 myy groupa 0 Sep 06:07filed
[[email protected] zgzdir]# chmod filed--Change the permissions of filed to
[Email protected] zgzdir]# ls-l
Total 8
-RWXRWXRWX 1 myy groupa 0 Sep 06:07filec
-rwxr-x---1 myy groupa 0 Sep 06:07filed     2. Use characters to change file permissions there is a way to change the permissions, we have learned that the file permissions are divided into three groups, respectively, User,group,others, then we can use U,g,o to represent three groups, in addition, a (all) represents all, and the permission attribute can be used r,w, X three characters to indicate, then look at the following syntax: chmod u/g/o/a + (Join)/-(remove)/= (set) r/w/x file or directory       Example:we want to get the filed file: U: Readable, writable, executableg,o: readable, executable[email protected] zgzdir]# ls-l
Total 8
-RWXRWXRWX 1 myy groupa 0 Sep 06:07filec
-rwxr-x---1 myy groupa 0 Sep 06:07filed
[[email protected] zgzdir]# chmod U=rwx,go=rx filed--Modify filed file properties
[[email protected] zgzdir] #ls-L
Total 8
-RWXRWXRWX 1 myy groupa 0 Sep 06:07filec
-rwxr-xr-x 1 myy groupa 0 Sep 06:07filedwhere G and O can also be separated by "," to set separately. Let's say I don't know the permissions of each group at the moment, just want all groups to add "x" permission, then we can use chmod a+xfilename to implement,Example: [email protected] zgz]# ls-l
Total 24
-rw-r--r--1 Myygroupa 0 Sep26 05:48 Filea
-rw-r--r--1 Myygroupa 3 Sep26 05:59 Fileb
-rw-r--r--1 Zgzgroupa 0 Sep26 06:39 Fileg
Drwxr-xr-x 2 myy groupa 4096 Sep 06:07zgzdir
[[email protected] zgz]# chmod a+x Filea--Modify Filea file attributes, all groups add "x" permission

[Email protected] zgz]# ls-l
Total 24
-rwxr-xr-x 1 Myygroupa 0 Sep26 05:48 Filea
-rw-r--r--1 Myygroupa 3 Sep26 05:59 Fileb
-rw-r--r--1 Zgzgroupa 0 Sep26 06:39 Fileg
Drwxr-xr-x 2 myy groupa 4096 Sep 06:07zgzdirIf you want to remove a permission, you can use "-" to manipulate it .Example:[Email protected] zgz]# ls-l
Total 24
-rwxr-xr-x 1 Myygroupa 0 Sep26 05:48 Filea
-rw-r--r--1 Myygroupa 3 Sep26 05:59 Fileb
-rw-r--r--1 Zgzgroupa 0 Sep26 06:39 Fileg
Drwxr-xr-x 2 myy groupa 4096 Sep 06:07zgzdir
[[email protected] zgz]# chmod a-x filea -Modify Filea file properties All groups remove the "x" Permission
[Email protected] zgz]# ls-l
Total 24
-rw-r--r--1 Myygroupa 0 Sep26 05:48 Filea
-rw-r--r--1 Myygroupa 3 Sep26 05:59 Fileb
-rw-r--r--1 Zgzgroupa 0 Sep26 06:39 Fileg
Drwxr-xr-x 2 myy groupa 4096 Sep 06:07zgzdir
[[Email Protected]edhat zgz]#
Friendly reminder: chgrp,chown,chmod These commands by default, only Root has permission to execute, you may sometimes use the ordinary account to modify the file permissions, Linux will prompt you do not have this permission. Therefore, we must pay attention to the current user, for example:[email protected] ~]$ chgrp GROUPB Filea
Chgrp:changing Group of ' Filea ': Operation notpermitted --zgz does not have permission to change the ' Filea ' group

Linux modifies the file owner and the group in which the file resides

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.