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文件系统下有效