umask, chmod, chown, chgrp for linux learning

//start-stop-daemon

 

1. umask sets the default permissions for any file or directory created, it provides a mask, umask is the value subtracted from the full permissions of the object, the full permission mode of the file is 666, and the full permission mode of the directory is 777 .
[root@ASM ~]# umask ----- umask value is 0022, where the first 0 means special security becomes sticky bit
0022
[root@ASM ~]# touch dong
[root@ASM ~]# ll|grep dong
-rw-r--r-- 1 root root 0 Jun 30 14:16 dong --- (666-022=644 is exactly rw-r--r--)
[root@ASM ~]# mkdir zhoudong
[ root@ASM ~]# ll|grep zhoudong
drwxr-xr-x 2 root root 4096 Jun 30 14:16 zhoudong --- (777-022=755 is exactly rwxr-xr-x)
2. The chmod command  -- is used for Change the permissions of files or directories
[root@ASM ~]# chmod 777 dong --Change the permissions of dong to rwxrwxrwx
[root@ASM ~]# ll|grep dong
-rwxrwxrwx 1 root root 0 Jun 30 14:16 dong
chmod u represents the user himself, g represents the user group, o represents other users, and a represents all users
[root@ASM ~]# chmod g+w zhoudong/ --Add read permission to user group
[root@ASM ~]# ll|grep dong
-rwxrwxrwx 1 root root 0 Jun 30 14:16 dong
drwxrwxr-x 2 root root 4096 Jun 30 14:16 zhoudong
[root@ASM ~]# chmod o+w zhoudong/ --add read permission for other users
[root@ASM ~]# ll|grep dong
-rwxrwxrwx 1 root root 0 Jun 30 14 :16 dong
drwxrwxrwx 2 root root 4096 Jun 30 14:16 zhoudong
3. chown command   --modify owner
[root@ASM ~]# ll|grep dong
-rwxrwxrwx 1 root root 0 Jun 30 14:16 dong
drwxrwxrwx 2 root root 4096 Jun 30 14:16 zhoudong
[root@ASM ~]# chown oracle:dba dong -- Change the owner and group of dong to oracle and dba
[root@ASM ~]# ll|grep dong
-rwxrwxrwx 1 oracle dba 0 Jun 30 14:16 dong
drwxrwxrwx 2 root root 4096 Jun 30 14:16 zhoudong
4. The chgrp command   -- the default group for modifying files
[root@ASM ~]# ll|grep hp
-rw- r--r-- 1 root root 0 Jun 30 14:38 hp
-rw-r--r-- 1 root root 5 Apr 11 23:38 xhp
[root@ASM ~]# chgrp dba hp --modify hp's The default group is dba
[root@ASM ~]# ll|grep hp
-rw-r--r-- 1 root dba 0 Jun 30 14:38 hp
-rw-r--r-- 1 root root 5 Apr 11 23 :38 xhp
5. Shared file linux provides suid bit and sgid bit (when suid is set, when the file is executed by the user, the program will run under the permission of the file owner; when sgid is set, the program will run under the permission of the file user group run)
[root@ASM ~]# mkdir testdir
[root@ASM ~]# ll|grep testdir
drwxr-xr-x 2 root root 4096 Jun 30 14:52 testdir ---User group has execute permission
[root@ASM ~]# chmod g+s testdir/ --- after adding gid, the small x becomes s
[root@ASM ~]# ll|grep testdir
drwxr-sr-x 2 root root 4096 Jun 30 14:52 testdir
[root@ASM ~]# ll|grep testdir ---User group does not have execute permission
drwxr--rx 2 root root 4096 Jun 30 14:52 testdir
[root@ASM ~]# chmod g+s testdir/ --- After adding the gid, the one that is executing becomes a big S
[root@ASM ~]# ll|grep testdir
drwxr-Sr-x 2 root root 4096 Jun 30 14:52 testdir

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326352203&siteId=291194637