chattr 設定linux檔案的屬性
(參照man手冊進行翻譯,常用的屬性都翻譯過來,個人覺得很少用到的屬性就沒有翻譯)
用法:chattr [ -RVf ] +-=[acdeijstuADST] files
選項:
-R 對目錄進行遞歸處理
-V 顯示詳細的輸出
-F 忽略大部分錯誤
屬性:
A 當一個檔案具有'A'屬性時,它的通路時間(atime)記錄不會再改變。這可以減少一定數量的I/O
操作
a 具有'a'屬性的檔案,隻能通過追加(>>)的方式向檔案寫内容。此屬性隻能有root使用者或者具有
調用CAP_LINUX_IMMUTABLE功能的程序來增加或删除
c 擁有'c'屬性的檔案在disk存儲時會通過kernel進行自動壓縮。讀操作傳回經過解壓縮的資料,寫
操作在寫入磁盤前會被壓縮。請關注文檔尾部關于此屬性的bug和局限性
D 當一個擁有'D'屬性的檔案被修改時,修改會實時的寫到磁盤(即不經過系統buffer);這等同于
mount時加上'dirsync'選項會對目錄下檔案産生的效果
S 當一個擁有'S'屬性的檔案被修改時修改會被實時的寫到磁盤,這等同于mount的'sync'選項對文
件的子集産生做效果一樣,
i 擁有'i'屬性的檔案,無法被删除或者重命名,也無法為此檔案建立連接配接檔案,亦無法寫入,隻有
root使用者或者具有調用CAP_LINUX_IMMUTABLE功能的程序來增加或删除
s 當一個擁有's'權限的檔案被删除時,他的檔案塊被歸零并寫回至磁盤。
注意:文檔尾部有此屬性bug和局限性相關介紹
T 擁有'T'權限的目錄,為了block allocator(我想可了解為磁盤的塊配置設定器)配置設定的目的,将會
被視為目錄層級的頂端。這是給了采用ext3和ext4檔案系統的block allocator一個示意--此目
錄下的子目錄都是不相關的,是以(這些子目錄)應該是分散開的,為了配置設定(我想應該是磁盤
配置設定block)的目的(這裡我想應該了解為這些子目錄在底層的block配置設定上應該是獨立開的)。
舉例:為/home目錄設定'T'權限是一個很好的主意,這樣/home/john和/home/mary就會被放在不
同的block group(塊組);如果沒有設定'T'權限,block allocator将會試着将相近的子目錄分
配在同一塊組如果可能的話。
t A file with the ’t’ attribute will not have a partial block fragment at
the end of the file merged with other files (for those filesystems
which support tail-merging). This is necessary for applications such
as LILO which read the filesystem directly, and which don’t understand
tail-merged files. Note: As of this writing, the ext2 or ext3 filesys-
tems do not (yet, except in very experimental patches) support tail-
merging.
d A file with the ‘d’ attribute set is not candidate for backup when the
dump(8) program is run.
e The ’e’ attribute indicates that the file is using extents for mapping
the blocks on disk. It may not be removed using chattr(1).
I The ’I’ attribute is used by the htree code to indicate that a direc-
tory is being indexed using hashed trees. It may not be set or reset
using chattr(1), although it can be displayed by lsattr(1).
H The ’h’ attribute indicates the file is storing its blocks in units of
the filesystem blocksize instead of in units of sectors, and means that
the file is (or at one time was) larger than 2TB. It may not be set or
reset using chattr(1), although it can be displayed by lsattr(1).
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 supe-
ruser or a process possessing the CAP_SYS_RESOURCE capability can set
or clear this attribute.
BUGS AND LIMITATIONS
'c','s','u'屬性在ext2和ext3檔案系統上并不完全“忠誠”在後續kernel的ext2和ext3檔案系統
中可能會有所改善
'D'屬性隻在Linux kernel 2.5.19及以後的kernel中使用
'j'屬性隻在3xt3檔案系統下有效
本文轉自kai404 51CTO部落格,原文連結:http://blog.51cto.com/kaifly/1567431,如需轉載請自行聯系原作者