Linux commands: chmod command

Source: Internet
Author: User

1. command format:

chmod [-CFVR] [--help] [--version] Mode file

2. command function:

Used to change the access rights of a file or directory, using it to control access to a file or directory.

3. Command parameters:

Necessary Parameters :
-C When a change occurs, the report processes the information
-F error Message not output
-R handles all files in the specified directory and its subdirectories
-V Run-time display verbose processing information

Select Parameters :
--reference=< directory or File > set to have the same permissions as the specified directory or file
--version displaying version information
< permissions >+< permissions settings > Allow directories or files within a permission scope to have the specified permissions
< permission scope >-< permission settings > Delete permission scope of directory or file specified permission
< permission range >=< permissions settings > Set permissions for a directory or a file in a permission range for a specified value

Permission Range :
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

Permission Code :
R: Read permission, denoted by the number 4
W: Write permission, denoted by the number 2
X: Execute permission, denoted by the number 1
-: Delete permission, denoted by the number 0
S: Special Permissions

There are two ways to use this command. One is a text-setting method that contains letters and operator expressions, and the other is a digital setting method that contains numbers.
1 ) . Text Setting Method :
chmod [who] [+ | - | =] [mode] File name
2 ) . Digital Setting Method
We must first understand the meaning of the attributes represented by numbers: 0 means no permissions, 1 means executable permissions, 2 is writable, 4 is read, and then it is added. So the format of the numeric attribute should be 3 octal numbers from 0 to 7, in the Order of (U) (g) (O).
For example, if you want the owner of a file to have "read/write" Two permissions, you need to have 4 (readable) +2 (writable) =6 (read/write).
The general form of the digital setting method is:
chmod [mode] file name

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.

Example 1 : Add file All user groups executable permissions

[Email protected]home]# ll

-rw-r--r--. 1 Rootroot 0 May 5 02:40 test.log

[[Email protected]home]# chmod a+x test.log "If you cancel the permission, set to A-x"

[Email protected]home]# ll

-rwxr-xr-x. 1 Rootroot 0 May 5 02:40 test.log

Example 2 : The permissions of other users are: Read, the permissions of the file owner are read, write, execute, the permissions of the group where the file owner is: Read, execute

[Email protected]home]# chmod 754 Test.log

[Email protected]home]# ll

-RWXR-XR--. 1 root root 0May 5 02:43 test.log

Note: If you add permissions to all files in a directory and its subdirectories, such as: Chmod–r a+x test

Linux commands: chmod command

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.