用戶身份與文件權(quán)限---文件的隱藏屬性
Linux系統(tǒng)中的文件除了具備一般權(quán)限和特殊權(quán)限外恕酸,還有一種隱藏權(quán)限卧抗,即被隱藏起來的權(quán)限,默認情況下不能直接被用戶發(fā)覺
1暖混,chattr
命令
chattr
命令用于設(shè)置文件的隱藏權(quán)限榄融,格式為 chattr [參數(shù)] 文件
参淫。
注意:
- 在命令后追加
+參數(shù)
,把某個隱藏功能加到文件上 - 在命令后追加
-參數(shù)
愧杯,把某個隱藏功能移除文件
chattr
命令中用于隱藏權(quán)限的參數(shù)及其作用
-
i
:無法對文件進行修改涎才;若對目錄設(shè)置了該參數(shù),則僅能修改其中的子文件內(nèi)容而不能新建或刪除文件 -
a
:僅容許補充(追加)內(nèi)容力九,無法覆蓋/刪除內(nèi)容(Append Only) -
S
:文件內(nèi)容在變更后立即同步到硬盤(sync) -
s
:徹底從硬盤中刪除耍铜,不可恢復(fù)(用0填充原文件所在硬盤區(qū)域) -
A
:不再修改這個文件或目錄的最后訪問時間 -
b
:不再修改文件或目錄的存取時間 -
D
:檢查壓縮文件中的錯誤 -
d
:使用dump命令備份時忽略本文件/目錄 -
c
:默認將文件或目錄壓縮 -
u
:當刪除該文件后依然保留其在硬盤中的數(shù)據(jù),方便日后恢復(fù) -
t
:讓文件系統(tǒng)支持尾部合并(tail-merging) -
x
:可以直接訪問壓縮文件中的內(nèi)容
示例:為文件增加隱藏權(quán)限a
[root@study doc]# echo "for test" > testfile
[root@study doc]# rm testfile
rm: remove regular file ‘testfile’? y
[root@study doc]# echo "for test" > testfile
[root@study doc]# chattr +a testfile
[root@study doc]# rm testfile
rm: remove regular file ‘testfile’? y
rm: cannot remove ‘testfile’: Operation not permitted
2跌前,lsattr
命令
lsattr
命令用于顯示文件的隱藏權(quán)限棕兼,格式為 lsattr [參數(shù)] 文件
示例:查看文件隱藏權(quán)限,刪除隱藏權(quán)限
[root@study doc]# lsattr testfile
-----a-------e-- testfile
[root@study doc]# chattr -a testfile
[root@study doc]# lsattr testfile
-------------e-- testfile
[root@study doc]# rm testfile
rm: remove regular file ‘testfile’? y