1.5.1.chmod
English original meaning: change the permissions mode of a file
Users who can modify file permissions: owner, root
grammar:
chomod [{ugoa} {+-=} {rwx}] [ file or directory ]
[mode=421] [ file or directory ]
-R recursively modify
u:User
g:group
o:other
a:all
+: add permission
-: Reduce permissions
=: delete all previous permissions and assign the current permissions
User increases execute permission
[root@localhost cn]# chmod u+x yum.log
[root@localhost cn]# ll
total 4
-rwx------. 1 root root 27 Apr 23 21:58 yum.log
User removes execute permission, group increases read and write execution, other increases execute permission
Multiple operations are separated by commas
[root@localhost cn]# chmod u-x,g+rwx,o+x yum.log
[root@localhost cn]# ll
total 4
-rw-rwx--x. 1 root root 27 Apr 23 21:58 yum.log
If you need to modify a directory and the permissions of all resources under the directory, you need to use the -R parameter
chomd –R /tmp
|
|
document |
content |
r |
read permission |
Can view file content |
Can list the contents of a directory |
w |
write permission |
file content can be modified |
Can create, delete files in a directory |
x |
execute permission |
executable file |
can enter the directory |
Create a directory test with root , with rwxrwxrwx permissions, if a file log.log is created in the test directory , with -rw-r--r--. permissions.
Can I delete the log.log file when I log in with a normal user ?
[root@localhost cn]# ll
total 4
drwxrwxrwx. 2 root root 21 Apr 24 20:44 test
-rw-rwx--x. 1 root root 27 Apr 23 21:58 yum.log
[root@localhost cn]# ll test/
total 0
-rw-r--r--. 1 root root 0 Apr 24 20:44 log.log
[root@localhost cn]#
The answer is that it can be deleted, because ordinary users have w permissions on the test directory
1.6. Other permission commands
1.6.1.chown
English original meaning: change file ownership
grammar:
chown [user] [file or directory]
A user who can change the owner of a file: root
1.6.2.chgrp
change file group ownership
chgrp [usergroup] [file or directory]
Change the group of a file or directory
1.6.3.umask
When creating a file, permission default information:
Whoever created the file is the owner of the file, and his group is the default group of the owner of the file
the user file-creation mask
Display and set default permissions for files
-S Displays the default permissions of new files in the form of rwx
[root@localhost cn]# umask -S
u = rwx, g = rx, o = rx
The execute permission of newly created files in Linux system will be removed, even if the umask configuration has execute permission
[root@localhost cn]# ll
total 4
drwxrwxrwx. 2 root root 21 Apr 24 20:44 test
-rw-rwx--x. 1 root root 27 Apr 23 21:58 yum.log
[root@localhost cn]# umask -S
u = rwx, g = rx, o = rx
[root@localhost cn]# mkdir test1
[root@localhost cn]# touch test2.log
[root@localhost cn]# ll
total 4
drwxrwxrwx. 2 root root 21 Apr 24 20:44 test
drwxr-xr-x. 2 root root 6 Apr 24 21:10 test1
-rw-r--r--. 1 root root 0 Apr 24 21:10 test2.log
-rw-rwx--x. 1 root root 27 Apr 23 21:58 yum.log
[root@localhost cn]#
The -S parameter may not be supported in older Linux systems
[root@localhost cn]# umask
0022
0: special permission
0:user
2:group
2:other
This is called a permission mask
777-022=755
The corresponding value is: rwxr-xr-x
If the default permissions are modified to: rwxr-xr—
which corresponds to 754
777-754=023
Execute the command: umask 023 is enough
[root@localhost cn]# umask
0022
[root@localhost cn]# umask 023
[root@localhost cn]# mkdir test3
[root@localhost cn]# ll -d test3/
drwxr-xr--. 2 root root 6 Apr 24 21:17 test3/