Linux commands: The difference between chmod, CHGRP, Chown

Source: Internet
Author: User
Tags chmod readable file permissions

Chmod is the right to change the file;

CHGRP only changes the group of files;

Chown is the owner and genus of the changed file.

1.chmod: Change permissions for a file

There are two ways to set file permissions, namely numbers and tags .

Mode: Permission to set the string, the pattern is as follows: [Ugoa ...] [[+-=][RWXX] ...] [,...], where u implies that the owner of the file, G implies that the owner of the file belongs to the Group (group), and O implies that the other person, a implies that all three are.

+ hint add permission,-hint to dismiss permission, = imply only set permission.

R implies readable, W implies writable, X implies can be implemented, x implies only if the file is a subdirectory, presumably the file has been set to be implemented.

-S: The file in which the Master or group ID of the process is placed as the file owner.

C: If the file's permissions have been changed, it will show its movement

-F: Do not display error messages if the file permissions cannot be changed

-V: Specific information on performance of permission changes

-r: All the files under the present catalog are subject to different permission changes (that is, one by one, in a recursive way).

--HELP: Performance Help statement

--version: Performance version

Example: Set the file file1.txt to be read by all people:

chmod ugo+r File1.txt

Set the file file1.txt to be read by all people:

chmod a+r File1.txt

The file file1.txt and File2.txt are set to the owner of the file, and the person to whom it belongs can be written to, but not to the others:

chmod ug+w,o-w file1.txt File2.txt

Set the ex1.py to be available only to the owner of the file:

chmod u+x ex1.py

Set all files and subdirectories under the present catalog to be readable by anyone:

Chmod-r A+r *

When another user implements Oracle's Sqlplus this French, his identity is temporarily spawned by this French Oracle

chmod u+s Sqlplus

In addition, chmod can also use numbers to imply permissions such as chmod 777 file

The syntax is: chmod ABC file

Each of these a,b,c is a number, and the table represents the permissions of the user, Group, and other.

R=4,w=2,x=1

To rwx the attribute then 4+2+1=7;

To rw-the attribute then 4+2=6;

To r-x the property, 4+1=5.

Example:

chmod a=rwx file and chmod 777 file results are not different;

chmod ug=rwx,o=x file and chmod 771 file results are not different;

Using chmod 4755 filename allows the program to have root privileges.

I generally give the newly uploaded file chmod 755 file.

2.CHGRP: Change the group of files or directories

command format:  chgrp The user group file name. If the entire directory is changed, the plus-r parameter is used for recursion.

#chgrp-R Guest/var/tmp/xx.txt

  #chgrp-R root/home/xx/yy/a.txt

3.chown: Change the owner and genus of a file

 Command format:

  A:chown-r-H User name file/Catalog

The-r option means that the same operation is done for files in all subdirectories, and the-h option means that the target file that the link points to is not affected when the owner of the symbolic link file is changed.

Note: Once ownership of a file is given to another user, it is no longer possible to reclaim its ownership and ultimately only to the system administrator.

B:chown User name: User group: File/Catalog

If the entire contents are changed, the plus-r parameter is used for recursion. Cases:

#chown Guest:guest A.txt

#chown Tomcat.root A.class

#chown-R Guest/home/berry (change all files under the Berry file to the guest group)

Linux commands: The difference between chmod, CHGRP, Chown

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.