Linux Second week study notes (TEN)
2.16 Umask
umask command: Used to change the default permissions for files and directories, in the format: umask * * * ( *** represents 3 number). View the value of umask umask you can.
By default, the file's permission values are: -rw-r--r-- ( 644 ), the permission value for the directory is: Drwxr-xr-x ( 755 ). What are the two permission values to be determined? This involves an idea called umask, which we can use to determine what the file's permission value is, or what the permission value of the directory is.
-------------------------------------------------------------------------------------------
[Email protected] tmp]# umask
0022
Root User's umask value (default value)
--------------------------------------------------------------------------------------------
Umask How it's calculated:
1. When a user creates an ordinary file, the preset does not have executable permissions, only R , W Two permissions, the maximum value is: 666-rw-rw-rw-
2. user to create a directory, the default all permissions are open, i.e. 777rwxrwxrwx
3. calculation method: The default value in the above two rules normal file is 666-rw-rw-rw- , catalog file is 777rwxrwxrwx need to subtract umask 0022----w-w )
The directory files are: rwxrwxrwx - ----w-w=rwxr-xr-x ( 755 )
The Common files are: -rw-rw-rw- - ----w-w=rw-r--r-- ( 644 )
[Email protected] tmp]# Mkdir-pv/tmp/daizhihong4
mkdir: The directory has been created "/tmp/daizhihong4"
[Email protected] tmp]# ls-l/tmp/daizhhong4
[Email protected] tmp]# ls-l
Total Dosage 8
-rw-r--r--1 root root 2564 1 Month 23:22 anaconda-ks.cfg.1
drwxr-xr-x 2 root root 1 Month 13:36 Daizhihong
d-wx--x---3 root root 1 Month 21:58 Daizhihong3
Drwxr-xr-x ( 755 ) 2 root root 6 1 months 21:48 Daizhihong4
drwxr-xr-x 5 yngndzh1 User 1 Month 11:43 Daizhong
[Email protected] tmp]# Touch/tmp/123,txt
[Email protected] tmp]# ls-l
Total Dosage 8
-rw-r--r-- ( 644 ) 1 root root 0 1 Month 21:52 123,txt
-rw-r--r--1 root root 2564 1 Month 23:22 anaconda-ks.cfg.1
drwxr-xr-x 2 root root 1 Month 13:36 Daizhihong
d-wx--x---3 root root 1 Month 21:58 Daizhihong3
drwxr-xr-x 2 root root 6 1 Month 21:48 Daizhihong4
drwxr-xr-x 5 yngndzh1 User 1 Month 11:43 Daizhong
----------------------------------------------------------------------------------------
Change umask values:
[Email protected] tmp]# umask
0022
[Email protected] tmp]#
[Email protected] tmp]# umask
0022
[Email protected] tmp]# umask 003
[Email protected] tmp]# umask
0003 (has been changed to 003 )
To view permissions for new files and directories:
[Email protected] tmp]# Touch/tmp/123456.txt
[Email protected] tmp]# mkdir-pv/tmp/daizhihong001
mkdir: The directory has been created "/tmp/daizhihong001"
[Email protected] tmp]# ls-l
Total Dosage 8
-rw-rw-r-- 1 root root 0 1 Month 23:46 123456.txt (file)
-rw-r--r--1 root root 2564 1 Month 23:22 anaconda-ks.cfg.1
drwxrwxr-- 2 root root 6 1 Month 23:47 daizhihong001 (catalogue)
-rwx------. 1 root root 836 1 Month 08:19 ks-script-9pf2we
drwx------3 root root 1 Month 21:46 systemd-private-
the permissions of the file become -rw-rw-r-664
Use numeric calculations: 666-003=663
The above can be seen cannot be converted into numbers to subtract, so sometimes error
the correct method of calculation should be :
-rw-rw-rw- - -------wx=-rw-rwr--=664 ( must be reduced by one )
the catalogue has become drwxrwxr - -------wx=rwxrwxr--=774
Linux Second week study notes (10)