當(dāng)我們創(chuàng)建一個(gè)文件或者目錄時(shí)即使我們未對其非配權(quán)限,其也會存在默認(rèn)權(quán)限
[root@localhost tmp]# mkdir newdir
[root@localhost tmp]# ls -dl newdir
drwxr-xr-x 2 root root 4096 02-21 11:10 newdir
[root@localhost tmp]# touch newfile
[root@localhost tmp]# ll newfile
-rw-r--r-- 1 root root 0 02-21 11:11 newfile
[root@localhost tmp]#
[root@localhost tmp]#
對于文件來說默認(rèn)的權(quán)限是 rw-r--r—
對于目錄來說默認(rèn)的權(quán)限是 rwxr-xr-x
語法:
查看默認(rèn)權(quán)限:umask [-S]
選項(xiàng)與參數(shù):-S 以符號形式顯示
設(shè)置默認(rèn)權(quán)限:umask 權(quán)限數(shù)
說明:對于目錄來說最大權(quán)限是777(rwxrwxrwx)
對于文件來說最大權(quán)限是666(rw-rw-rw-)
當(dāng)權(quán)限數(shù)為022時(shí)代表:目錄權(quán)限(777-022)=755(rwxr-xr-x)
當(dāng)權(quán)限數(shù)為022時(shí)代表:目錄權(quán)限(666-022)=644(rw-r--r—)
舉例:查看默認(rèn)權(quán)限
[ro[root@localhost tmp]# umask
0022
[root@localhost tmp]# umask -S
u=rwx,g=rx,o=rx
舉例:設(shè)置默認(rèn)權(quán)限
[root@localhost tmp]# umask 011
[root@localhost tmp]# mkdir newdir1
[root@localhost tmp]# ls -dl newdir1
drwxrw-rw- 2 root root 4096 02-21 13:09 newdir1
[root@localhost tmp]# touch newfile1
[root@localhost tmp]# ll newfile1
-rw-rw-rw- 1 root root 0 02-21 13:10 newfile1
語法:chattr [+-=][ASacdistu]文件或目錄名稱
選項(xiàng)與參數(shù):
+:增加某一個(gè)特殊參數(shù)
-:刪除某一個(gè)特殊參數(shù)
=:僅有后面接的參數(shù)
A:當(dāng)配置了 A 這個(gè)屬性時(shí),若你有存取此文件(或目錄)時(shí),他的存取時(shí)間 atime 將不會被修改,可避免 I/O 較慢的機(jī)器過度的存取磁碟。這對速度較慢的計(jì)算機(jī)有幫助
S:一般文件是非同步寫入磁碟的(原理請參考第五章 sync 的說明),如果加上 S 這個(gè)屬性時(shí),當(dāng)你進(jìn)行任何文件的修改,該更動會[同步]寫入磁碟中。
a:當(dāng)配置 a 之后,這個(gè)文件將只能添加數(shù)據(jù),而不能刪除也不能修改數(shù)據(jù),只有 root 才能配置這個(gè)屬性。
c:這個(gè)屬性配置之后,將會自動的將此文件『壓縮』,在讀取的時(shí)候?qū)詣咏鈮嚎s, 但是在儲存的時(shí)候,將會先進(jìn)行壓縮后再儲存(看來對於大文件似乎蠻有用的!)
d:當(dāng) dump 程序被運(yùn)行的時(shí)候,配置 d 屬性將可使該文件(或目錄)不會被 dump 備份
i:可以讓一個(gè)文件[不能被刪除、改名、配置連結(jié)也無法 寫入或新增數(shù)據(jù)!]對與系統(tǒng)安全性有相當(dāng)大的助益!只有 root 能配置此屬性
s:當(dāng)文件配置了 s 屬性時(shí),如果這個(gè)文件被刪除,他將會被完全的移除出這個(gè)硬盤空間,所以如果誤刪了,完全無法救回來了喔!
u:與 s 相反的,當(dāng)使用 u 來配置文件時(shí),如果該文件被刪除了,則數(shù)據(jù)內(nèi)容其實(shí)還存在磁碟中,可以使用來救援該文件
舉例:
[root@localhost tmp]# nano
[root@localhost tmp]# ll testa
-rw-r--r-- 1 root root 5 02-21 13:24 testa
[root@localhost tmp]# chattr +a testa
[root@localhost tmp]# nano testa //此處修改不允許保存
[root@localhost tmp]# chattr =i testa
[root@localhost tmp]# rm testa
rm:是否刪除有寫保護(hù)的 一般文件 “testa”? y
rm: 無法刪除 “testa”: 不允許的操作
語法:lsattr [-adR] 文件或目錄
選項(xiàng)與參數(shù):
-a:將隱藏文件列出來
-d:如果接的是目錄,僅列出目錄本身屬性而非目錄內(nèi)的文件名
-R:連同子目錄的數(shù)據(jù)也一并列出來
語法:file 文件
[root@localhost tmp]# file ~/.bashrc
/root/.bashrc: ASCII text