linux chattr命令
chattr? 設(shè)置linux文件的屬性?
(參照man手冊進(jìn)行翻譯,常用的屬性都翻譯過來,個人覺得很少用到的屬性就沒有翻譯)
用法:chattr [ -RVf ] +-=[acdeijstuADST] files
選項:
? -R? 對目錄進(jìn)行遞歸處理
? -V? 顯示詳細(xì)的輸出
? -F? 忽略大部分錯誤
屬性:
?? A? 當(dāng)一個文件具有'A'屬性時,它的訪問時間(atime)記錄不會再改變。這可以減少一定數(shù)量的I/O
????? 操作
?? a? 具有'a'屬性的文件,只能通過追加(>>)的方式向文件寫內(nèi)容。此屬性只能有root用戶或者具有
????? 調(diào)用CAP_LINUX_IMMUTABLE功能的進(jìn)程來增加或刪除
?? c? 擁有'c'屬性的文件在disk存儲時會通過kernel進(jìn)行自動壓縮。讀操作返回經(jīng)過解壓縮的數(shù)據(jù),寫
????? 操作在寫入磁盤前會被壓縮。請關(guān)注文檔尾部關(guān)于此屬性的bug和局限性
?? D? 當(dāng)一個擁有'D'屬性的文件被修改時,修改會實時的寫到磁盤(即不經(jīng)過系統(tǒng)buffer);這等同于
????? mount時加上'dirsync'選項會對目錄下文件產(chǎn)生的效果
?? S? 當(dāng)一個擁有'S'屬性的文件被修改時修改會被實時的寫到磁盤,這等同于mount的'sync'選項對文
????? 件的子集產(chǎn)生做效果一樣,
?? i? 擁有'i'屬性的文件,無法被刪除或者重命名,也無法為此文件創(chuàng)建連接文件,亦無法寫入,只有
????? root用戶或者具有調(diào)用CAP_LINUX_IMMUTABLE功能的進(jìn)程來增加或刪除
?? s? 當(dāng)一個擁有's'權(quán)限的文件被刪除時,他的文件塊被歸零并寫回至磁盤。
????? 注意:文檔尾部有此屬性bug和局限性相關(guān)介紹
?? T? 擁有'T'權(quán)限的目錄,為了block? allocator(我想可理解為磁盤的塊分配器)分配的目的,將會
????? 被視為目錄層級的頂端。這是給了采用ext3和ext4文件系統(tǒng)的block? allocator一個示意--此目
????? 錄下的子目錄都是不相關(guān)的,因此(這些子目錄)應(yīng)該是分散開的,為了分配(我想應(yīng)該是磁盤
????? 分配block)的目的(這里我想應(yīng)該理解為這些子目錄在底層的block分配上應(yīng)該是獨立開的)。
????? 舉例:為/home目錄設(shè)置'T'權(quán)限是一個很好的主意,這樣/home/john和/home/mary就會被放在不
????? 同的block group(塊組);如果沒有設(shè)置'T'權(quán)限,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文件系統(tǒng)上并不完全“忠誠”在后續(xù)kernel的ext2和ext3文件系統(tǒng)
????? 中可能會有所改善
? ? ? 'D'屬性只在Linux kernel 2.5.19及以后的kernel中使用
? ? ? 'j'屬性只在3xt3文件系統(tǒng)下有效 ?
??
??
??
??
轉(zhuǎn)載于:https://blog.51cto.com/kaifly/1567431
總結(jié)
以上是生活随笔為你收集整理的linux chattr命令的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: E. Mocha and Stars(莫
- 下一篇: 网络设备自动化运维工具——Nornir3