The chmod of Linux

Source: Internet
Author: User

File/directory permission settings command: chmod

This is one of the most common commands used by Linux system administrators to change the access rights of a file or directory. There are two ways to use this command:

Using text-setting methods that contain letters and operator expressions

The syntax format is: chmod [who] [opt] [mode] File/directory Name

Where who represents an object, is one or a combination of the following letters:

U: Represents the file owner
G: Indicates the same group of users
O: Indicates another user
A: Indicates all users
Opt is representative of the operation and can be:
+: Add a permission
-: Cancel a permission
=: gives the given permission and cancels the original permission
mode, however, represents the authority:
R: Readable
W: Writable
X: Executable

For example: Add read and Write permissions to the file a.txt for the same group of users:

chmod G+RW A.txt

Using the Digital setting method

and the digital setting rule is simpler: chmod [mode] file name

The key is the value of mode, at first many beginners will be confused, in fact, it is very simple, we will rwx as a binary number, if there are 1 said, no 0 said, then rwx r-x R-can be expressed as:

111 101 100

Then convert every three bits into a decimal number, which is 754.

For example, we want a.txt this file to have the following permissions:

Other users of the same group as themselves
Is readable yes Yes Yes
Writable Yes Yes executable

So, we first get permission string according to the above table: rw-rw-r--, then convert to binary number is 110 110 100, and then every three bits into a decimal number, we get 664, so we execute the command:

chmod 664 A.txt


############################################################################
Directive Name: chmod
Usage rights: All users
Mode of use: chmod [-CFVR] [--help] [--version] Mode file ...
Description: Linux/unix's file invocation permissions are divided into three levels: file owners, groups, and others. The use of chmod can be used to control how files are called by others.
Parameters:
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 this program root privileges


The chmod of Linux

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.