Summary of usage of Linux chmod

Source: Internet
Author: User

Directive Name: chmod

Usage rights: All users

Mode of use: chmod [-CFVR] [--help] [--version] Mode file ...

Description: Linux/unix file access rights are classified into three levels: file owners, groups, and others. The use of chmod can be used to control how files are accessed by others.

Parameter format:

Mode: Permission set string in the following format: [Ugoa ...] [[+-=][RWXX] ...] [,...], where

U represents the owner of the file, G means that the owner of the file belongs to the same group (group), and O indicates that the other person, a means that all three are.

+ indicates an increase in permissions,-represents a cancellation permission, = Represents a unique set of permissions.

R is readable, w means writable, x is executable, x means only if the file is a subdirectory, or the file has been set as executable. -C: If the file permissions have changed, the change action will be displayed

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

-V: Show details of permission changes

-r: The same permissions change for all files in the current directory and subdirectories (that is, they are changed in a recursive manner)

--HELP: Show Auxiliary Instructions

--version: Display version

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

chmod ugo+r File1.txt

Set the file file1.txt to be readable by everyone:

chmod a+r File1.txt

The file file1.txt and File2.txt are set as the owner of the file, and the same group as the person to which they belong can be written, but others other than the other are not writable:

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

Set ex1.py to only the owner of the file can perform:

chmod u+x ex1.py

Set all files and subdirectories in the current directory to be readable by anyone:

Chmod-r A+r *

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

The syntax is: chmod ABC file

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

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=7.

Example:

chmod a=rwx File

And

chmod 777 File

Same effect

chmod ug=rwx,o=x File

And

chmod 771 File

Same effect

Use chmod 4755 filename to give the program root privileges

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.