天天看點

Linux裡建立檔案/目錄的預設權限

Linux裡建立檔案/目錄的預設權限

建立檔案預設權限為666,建立目錄預設權限為777。但是要"減去" umask的值,umask的值可以使用umask指令看到,一般情況下,root使用者的為022,普通使用者為002。這裡的"減"并非數字上相減,而是減去相應的權限。如果umask為022,則表示:user不減權限,group減掉write權限,other減掉write權限;如果umask為245,表示:user 減去write權限,group減去read權限,other減去read和execute權限。

示例1, root使用者umask為022,建立檔案和目錄後預設的權限

[email protected]:/tmp# umask

0022

[email protected]:/tmp# touch file1

[email protected]:/tmp# ls -l file1

-rw-r--r-- 1 root root 0 Aug 20 17:07 file1

[email protected]:/tmp# mkdir dir1

[email protected]:/tmp# ls -ld dir1/

drwxr-xr-x 2 root root 4096 Aug 20 17:12 dir1/

示例2,普通使用者umask為002:

[email protected]:/tmp$ umask

0002

[email protected]:/tmp$ touch file2

[email protected]:/tmp$ ls -l file2

-rw-rw-r-- 1 qingsong qingsong 0 Aug 20 17:11 file2

[email protected]:/tmp$ mkdir dir2

[email protected]:/tmp$ ls -ld dir2

drwxrwxr-x 2 qingsong qingsong 4096 Aug 20 17:13 dir2

示例3,一個極端的情況,将umask設定為666,則建立檔案沒有“任何"權限:

[email protected]:/tmp# umask 666

[email protected]:/tmp# umask

0666

[email protected]:/tmp# touch file3

[email protected]:/tmp# ls -l file3

---------- 1 root root 0 Aug 20 17:16 file3

繼續閱讀