Linux Command--chmod command &chgrp command &chown command

Source: Internet
Author: User

The chmod command is a command used to change file or folder permissions

Use the method for chmod [who] [+ |-| =] [mode] File name

The mode method is as follows:

The numbers correspond to characters as follows:

R=4,w=2,x=1
To rwx the property, 4+2+1=7
To rw-the attribute then 4+2=6;
To r-x the property, 4+1=7.

The WHO permission groups have the following relationships:

u: The current user of the directory or file
G: The current group of directories or files
o: Users or groups other than the current user or group of directories or files
A: All Users and Groups

Example 1 indicates to the current user, the current group to increase write permissions to the non-current users and groups to increase the execution rights.

chmod ug+w,o-x Test

Example 2 Remove all user Execute permissions

chmod a-x Test

Example 3 Adding the current user execution permission to the Test4 folder recursion

Chmod-r u+x test4

Example 4 gives the owner of the file read, write, execute (7) permissions, assign Read, execute (5) permissions to the group where the file is located, and assign execution (1) permissions to other users

chmod 751 file chmod u=rwx,g=rx,o=x file

Example 5 reserved read-only permission for all users

chmod =r file chmod 444 file chmod a-wx,a+r file


The CHGRP command is a user group used to change a file or file, and the corresponding user group can view it in etc/groups

Example 1 indicates that the user group for the Test2 file is changed to be the same as Test1

Chgrp--reference=test1 Test2

Example 2 recursively change the user group to bin for all files under the Test6 folder, where the 100-bit bin user group code

Chgrp-r bin Test6chgrp-r Test6

The Chown command is used to change the user or user group of the comment file or folder. The user can be a user name or a user ID; a group can be a group name or a group ID; a file is a list of files separated by spaces to change permissions, support wildcards, and use the format chown [options] ... Owner [: [Group]] file ...

Example 1 The user who changed the test file is root and the user group is

Chown Root:user Test

Example 2 The user who changed the test file is root and the user group is root

Chown Root:test

Example 3 changing the user group for the test file

Chown:user Test

Example 4: Change the user root of all files under the Test6 folder to user group

Chown-r-V Root:user test6

Reference Documentation:

Http://www.cnblogs.com/peida/archive/2012/11/29/2794010.html

Http://www.cnblogs.com/peida/archive/2012/12/03/2799003.html

Http://www.cnblogs.com/peida/archive/2012/12/04/2800684.html


Linux Command--chmod command &chgrp command &chown command

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.