1.chomd Commands
File permissions calling Linux / Unix is divided into three levels: file owner, group, others.
chmod command is used to change the access linux file system or directory. Use it to control access to the file or directory. This command has two uses. One is operator expression comprising letters and character set method; the other is a method comprising setting a digital number.
Usage rights : All users
2. Grammar
chmod [-cfvR] [--help] [--version] mode file...
3. Parameter Description
mode: permissions string in the following format:
[ Ugoa ...] [[+ - =] [ rwxX ] ...] [...]
3. Command parameters:
Necessary parameters:
-c when a change occurs, the report processing information
-f error information is not outputted
-R processing of all files in the specified directory and its subdirectories
display detailed processing information -v runtime
selection parameters:
specified directory or file --reference = <directory or file> is arranged to have the same authority
--version display version information
<purview> + <permissions> so that within the purview of directories or files having the specified permission
<purview > - <permissions> assign permissions to delete the file or directory purview of
<purview> = <permissions> directory or file permissions within the purview of the specified set value
Competence:
u: current user directory or file
g: current directory or file group
o: user or group other than the current directory or file or user group
a: all user and group
permissions code:
r: read permission, represented by numeral 4
w: write permission, by numeral 2
x: execute permissions, represented by numeral 1
-: delete permissions, represented by numbers 0
S: Special permissions
This command has two uses. One is operator expression comprising letters and character set method; the other is a method comprising setting a digital number.
1) character set method:
chmod [who] [+ | - | =] [mode] filename
2) digital setting method
We must first understand the properties of the numerical meaning: 0 means no permission and 1 for execute permission, 2 for write permission, 4 for read permission, and then added. So digital format attribute should be from three octal number from 0 to 7, which is a sequence (u) (g) (o).
For example, if you want the owner of a file are "read / write" two jurisdiction, need to 4 (read) + 2 (write) = 6 (read / write).
The general form for the digital setting method:
chmod [mode] filename
Digital correspondence between the characters are as follows:
r = 4, w = 2, x = 1
to rwx attribute is 4 + 2 + 1 = 7
to the properties rw- 4 + 2 = 6;
To the attributes rx 1 = 4 + 7.
4. Examples
Example 1: Increase the file executable permissions for all user groups
command:
chmod a+x log2012.log
Output:
[root@localhost test]# ls -al log2012.log
-rw-r--r-- 1 root root 302108 11-13 06:03 log2012.log
[root@localhost test]# chmod a+x log2012.log
[root@localhost test]# ls -al log2012.log
-rwxr-xr-x 1 root root 302108 11-13 06:03 log2012.log
[root@localhost test]#
Description:
I.e., setting file attributes for the log2012.log: file owner (u) increases execute permission; with the same file owner user group (g) increasing execute permission; other users (o) increases execute permissions.
Example 2: also modify the different user rights
command:
chmod ug+w,o-x log2012.log
Output:
[root@localhost test]# ls -al log2012.log
-rwxr-xr-x 1 root root 302108 11-13 06:03 log2012.log
[root@localhost test]# chmod ug+w,o-x log2012.log
[root@localhost test]# ls -al log2012.log
-rwxrwxr-- 1 root root 302108 11-13 06:03 log2012.log
Description:
That document set text attributes are: file owner (u) increased write permissions; the owner of the file with the user group (g) increased write permissions; other users (o) deleted execute permissions
Example 3: Delete the file permissions
command:
chmod a-x log2012.log
Output:
[root@localhost test]# ls -al log2012.log
-rwxrwxr-- 1 root root 302108 11-13 06:03 log2012.log
[root@localhost test]# chmod a-x log2012.log
[root@localhost test]# ls -al log2012.log
-rw-rw-r-- 1 root root 302108 11-13 06:03 log2012.log
Description:
Delete all user executable permission
Example 4: Use "=" Set Permissions
command:
chmod u=x log2012.log
Output:
[root@localhost test]# ls -al log2012.log
-rw-rw-r-- 1 root root 302108 11-13 06:03 log2012.log
[root@localhost test]# chmod u=x log2012.log
[root@localhost test]# ls -al log2012.log
---xrw-r-- 1 root root 302108 11-13 06:03 log2012.log
Description:
All rights revoked the original, then the owner has read permission
Example 5: Adding permissions to all files in a directory and its subdirectories
command:
chmod -R u+x test4
Output:
[root@localhost test]# cd test4
[root@localhost test4]# ls -al
Total 312drwxrwxr-x 2 root root 4096 11-13 05:50.
drwxr-xr-x 5 root root 4096 11-22 06:58 ..
-rw-r--r-- 1 root root 302108 11-12 22:54 log2012.log
-rw-r--r-- 1 root root 61 11-12 22:54 log2013.log
-rw-r--r-- 1 root root 0 11-12 22:54 log2014.log
[root@localhost test4]# cd ..
[root@localhost test]# chmod -R u+x test4
[root@localhost test]# cd test4
[root@localhost test4]# ls -al
Total 312drwxrwxr-x 2 root root 4096 11-13 05:50.
drwxr-xr-x 5 root root 4096 11-22 06:58 ..
-rwxr--r-- 1 root root 302108 11-12 22:54 log2012.log
-rwxr--r-- 1 root root 61 11-12 22:54 log2013.log
-rwxr--r-- 1 root root 0 11-12 22:54 log2014.log
Description:
Recursively assign permissions to the owner of all files and subdirectories under the directory test4
Some other examples:
Anyone can file file1.txt to read:
chmod ugo+r file1.txt
Anyone can file file1.txt to read:
chmod a+r file1.txt
The file file1.txt with file2.txt set the file owner, it belongs with a group who can write, but others can not be a person other than write:
chmod ug+w,o-w file1.txt file2.txt
The ex1.py set only the file owner can execute:
chmod u+x ex1.py
Anyone under the current directory of all the files and subdirectories are set to read:
chmod -R a+r *
In addition chmod you can also use numbers to represent rights such as:
chmod 777 file
The syntax is:
chmod abc file
Wherein a, b, c are each a number, respectively permissions User, Group, and the Other.
r=4,w=2,x=1
- To the property rwx 4 + 2 + 1 = 7;
- To rw- property is 4 + 2 = 6;
- To the property rx 1 = 4 + 5.
chmod a=rwx file
with
chmod 777 file
The same effect
chmod = rwx , o = x file
with
chmod 771 file
The same effect
If this program can use chmod 4755 filename have root privileges