linux chattr命令

简介:

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,如需转载请自行联系原作者



相关文章
|
16天前
|
Web App开发 Linux 网络安全
工作中常用到的Linux命令
工作中常用到的Linux命令
|
16天前
|
Web App开发 Java Linux
Linux之Shell基本命令篇
Linux之Shell基本命令篇
Linux之Shell基本命令篇
|
3天前
|
机器学习/深度学习 缓存 监控
linux查看CPU、内存、网络、磁盘IO命令
`Linux`系统中,使用`top`命令查看CPU状态,要查看CPU详细信息,可利用`cat /proc/cpuinfo`相关命令。`free`命令用于查看内存使用情况。网络相关命令包括`ifconfig`(查看网卡状态)、`ifdown/ifup`(禁用/启用网卡)、`netstat`(列出网络连接,如`-tuln`组合)以及`nslookup`、`ping`、`telnet`、`traceroute`等。磁盘IO方面,`iostat`(如`-k -p ALL`)显示磁盘IO统计,`iotop`(如`-o -d 1`)则用于查看磁盘IO瓶颈。
|
13天前
|
NoSQL Linux Shell
常用的 Linux 命令
常用的 Linux 命令
35 9
|
1天前
|
Ubuntu Linux Shell
linux免交互登陆远程主机并执行命令(密钥对和Expect)
linux免交互登陆远程主机并执行命令(密钥对和Expect)
|
1天前
|
Linux
【Linux】常用命令
【Linux】常用命令
14 0
|
1天前
|
安全 Ubuntu Linux
Linux 网络操作命令Telnet
Linux 网络操作命令Telnet
7 0
Linux 网络操作命令Telnet
|
2天前
|
Linux 数据安全/隐私保护
Linux常用命令实例带注释
Linux常用命令实例带注释
28 0
|
2天前
|
Linux 开发工具 数据安全/隐私保护
Linux(19)常用解压命令记录
Linux(19)常用解压命令记录
7 0
|
3天前
|
Linux Perl
Linux系统替换字符串常用命令
请注意,`sed`命令可以非常强大,可以根据不同的需求使用不同的选项和正则表达式来进行更复杂的字符串替换操作。
16 0