Linux文件的隱藏屬性在保護系統文件的安全性上非常重要。先強調的是,chattr命令只能在Ext2/Ext3的文件系統生效。
chattr(設置文件的隱藏屬性)
[root@www ~]# chattr [+-=] [ASacdistu] File/Directory
參數
+:增加某個參數
-:刪除某個參數
=:僅有后面接的參數
各個參數的意思
參數 | 含義 |
A | 設置A屬性后,若你訪問此文件或目錄時,它的訪問時間atime不會被修改,可避免I/O較慢的機器過度訪問磁盤。這對速度較慢的計算機有幫助。 |
S | 一般文件是異步寫入磁盤,加上S屬性后,文件將同步寫入磁盤 |
a | 當設置a后,文件只能增加數據,既不能刪除也不能修改數據,只有root才能設置這個屬性 |
c | 設置c屬性后,會自動將文件壓縮,在讀取時自動解壓縮 |
d | 當dump程序執行時,設置d屬性將可使改文件或目錄不被dump備份 |
i | i屬性可使文件不能被刪除、改名,設置連接也無法寫入或添加數據。對於系統安全性有很大幫助。只有root能設置此屬性。 |
s | 當文件設置s屬性時,如果文件被刪除,將從硬盤徹底刪除 |
u | 與s相反,當文件設置u屬性時,文件刪除后數據內容還存在磁盤,可以使用來找回該文件 |
j | A file with the `j' attribute has all of its data written to the ext3 journal before being written to the file itself, if the filesystem is mounted with the "data=ordered" or "data=writeback" options. When the filesystem is mounted with the "data=journal" option all file data is already journalled and this attribute has no effect. Only the superuser or a process possessing the CAP_SYS_RESOURCE capability can set or clear this attribute. |
lsattr(顯示文件隱藏屬性)
[root@www ~]# lsattr [-adR] File/Directory
參數
-a:將隱藏文件的屬性也顯示出來
-d:如果接的是目錄,僅列出目錄本身的屬性而不是目錄內的文件名
-R:連同子目錄的數據也顯示出來
使用范例
[root@www ~]# chattr +aij attrtest
[root@www ~]# lsattr attrtest
----ia---j--- attrtest
References
- 《鳥哥的Linux私房菜》,第7章,Linux文件與目錄管理