Previous section review:
1. Enter directory: cd command
2. Create directory: mkdir command
3. Delete directory: rmdir command
4. File and directory replication: CP
Jobs: Create a directory test1,test2, create a test1.txt file in Test1, and then copy the Test1.txt file to the Test2 folder
mkdir test1
mkdir test2
CD Test1
Touch Test1.txt
CP Test1.txt/test2
The content of this section:
1. File/ directory detail Information
When you view the file/directory details with the LL command, you can see information similar to the following
I use the red box to divide this information into 7 columns, the following are respectively explained
First column: File Types and Permissions
A total of 10 horizontal lines, the first represents the file type, commonly used file types:
D: Folder
-: Normal file
L: Links (Windows-like shortcuts)
B: block device files (e.g. hard drives, optical drives, etc.)
P: Pipeline File
C: Character device files (e.g. serial devices such as cats)
S: Set of interface files/data interface files (e.g. a Mysql.sock file is generated when starting a MySQL server)
The following 9 each of the 3 groups to represent the file owner, all groups of files, permissions of other users, the desirable values of permissions:
R= Read Property//value =4
W= Write property//value =2
X= Execution Properties//value =1
Display when a location is empty--indicates that this permission is not available
Second column: Number of connections
In addition to the directory file, all other files have 1 links
The number of connections to the directory file is +2 of the total number of other directories in this directory, for example, directory A contains the B and C directories, and the number of links in directory A is 4.
Third column: File owner
Fourth column: All groups of files
Fifth Column: File size
Sixth column: Latest modification time
Seventh column: File name
2. Change file permissions: chmod Command
Permissions in the use of U,g,o, respectively, for the file owner, the group, other people, permissions with rwx, increase the permissions with the + number, delete the permission with-number, specify the permission with the = number
Chmod u+w filename #表示给文件所有者添加写权限
Chmod u-w filename #表示删除文件所有者的写权限
Chmod u=rwx filename #表示设置文件所有者的权限为可读, writable, executable
Chmod u+w,g+w #filename #表示文件所有者添加写权限, all groups Add Write permissions
To set the permissions of everyone at the same time, you can use a number to indicate that rwx with 7, R with 4,-w-with 2,--x means 1.
Chmod 741 filename #表示所有者有读写执行的权限, all groups have Read permissions, others have permissions to execute.
In Test.txt, for example, the default permissions are as follows:
Now change the permissions, add permissions to the owner, add write permissions to all groups and others, execute
chmod u+x,g+w,o+w Test.txt
Similarly, we can also use the number to modify permissions, for example, to change the Test.txt permissions to U,g,o have RWX permissions, which can be used chmod 777 Test.txt
Finally, change the Test.txt authority to the original state, chmod u=rw,g=r,o=r test.txt
If you want to change the permissions of the directory and its sub-files, you need to use the-R parameter
For example, in the test folder, you can see the default permissions:
Permission to modify the directory is G with W
Chmod–r g+w Test
Other operations are consistent with the file, and finally change the permissions of test to default, execute Chmod–r g-w test
3. Change the file owner: chown Command
Basic usage chown owner: Owning group file name, or Chown–r owner: owning Group directory name
For example, to modify the file Test.txt the owner of the User1 is used: Chown user1 test.txt
To modify the file Test.txt the owning group for User1 is used: Chown:user1 test.txt
To modify both the owner and the owning group, use: Chown user1:user1 test.txt
To modify the ownership of the directory and its subkeys, you need to use the-R parameter, such as modifying the directory test and the owner of the child file as User1, using: Chown–r user1 test
4. Change the file owning group: chgrp Command
The basic user is similar to chown, except that this command modifies only the user's group, basic usage chgrp group name file name, or chgrp–r group name directory
Job: Create file Test.txt, modify the file permissions for the owner has read and write permissions, all groups have read and write permissions, other people have access to the permission to change the file owner is User1
Free video tutorial on public number "get kicked genius" gets
Linux Command Learning Series 10-use of permission-related CHOWN,CHMOD,CHGRP commands