lsattr
查看文件的隐藏属性
如何安装
# centos7-2# yum 源安装yum -y install e2fsprogs
常用命令
# 查看某个文件夹下文件的隐藏属性lsattr <dir>########################### 说明: 一般文件么有任何说明 ###########################e.g[root@1-1 ~]# lsattr /tmp----ia---------- /tmp/001.txt---------------- /tmp/lsattr.txt---------------- /tmp/chattr.txt# 查看某个文件夹下所有文件的隐藏属性lsattr -a <dir>e.g[root@1-1 ~]# lsattr -a /tmp---------------- /tmp/.---------------- /tmp/..---------------- /tmp/.Test-unix---------------- /tmp/.XIM-unix---------------- /tmp/.ICE-unix# 查看某个文件的隐藏属性lsattr <filename>e.g[root@1-1 ~]# lsattr /tmp/001.txt----ia---------- /tmp/001.txte.g# 查看某个文件夹下所有文件及子目录的所有隐藏属性[root@1-1 ~]# lsattr -aR /tmp---------------- /tmp/.---------------- /tmp/..---------------- /tmp/.Test-unix/tmp/.Test-unix:---------------- /tmp/.Test-unix/.---------------- /tmp/.Test-unix/..---------------- /tmp/.XIM-unix----ia---------- /tmp/001.txt
说明详情
LSATTR(1) General Commands Manual LSATTR(1)NAMElsattr - list file attributes on a Linux second extended file systemSYNOPSISlsattr [ -RVadv ] [ files... ]DESCRIPTIONlsattr lists the file attributes on a second extended file system. See chattr(1) for a description of theattributes and what they mean.OPTIONS-R Recursively list attributes of directories and their contents.-V Display the program version.-a List all files in directories, including files that start with `.'.-d List directories like other files, rather than listing their contents.-v List the file's version/generation number.AUTHORlsattr was written by Remy Card <Remy.Card@linux.org>. It is currently being maintained by Theodore Ts'o<tytso@alum.mit.edu>.BUGSThere are none :-).AVAILABILITYlsattr is part of the e2fsprogs package and is available from http://e2fsprogs.sourceforge.net.SEE ALSOchattr(1)E2fsprogs version 1.42.9 December 2013 LSATTR(1)
chattr
修改文件或文件夹隐藏属性
属性说明
| 参数 | 参数说明 |
|---|---|
| +-= | 分别为 [+ 增加] [- 减少] [= 设定] 属性的意思 |
| A | 当设定了 A 这个属性时,这个档案(或目录)的存取时间 atime (access) 将不可被修改, 可避免例如手提式计算机容易有磁盘 I/O 错误的情况发生! |
| S | 这个功能有点类似 sync 的功能!就是会将数据同步写入磁盘当中!可以有效的避免数据流失! |
| a | 当设定 a 之后,这个档案将只能增加数据,而不能删除,只有 root 才能设定这个属性。 |
| c | 这个属性设定之后,将会自动的将此档案『压缩』,在读取的时候将会自动解压缩出来,但是在储存的时候,将会先进行压缩之后再储存(看来对于大档案似乎蛮有用的!) |
| d | 当 dump (备份)程序被执行的时候,设定 d 属性将可使该档案(或目录)具有 dump 功效! |
| i | 这个 i 可就很厉害了!他可以让一个档案『不能被删除、改名、设定连结也无法写入或新增数据!对于系统安全性有相当大的帮助! |
| j | 当使用 ext3 这个档案系统格式时,设定 j 属性将会使档案在写入时先记录在 journal 中! 但是当 filesystem 设定参数为 data=journalled 时,由于已经设定了日志了,所以这个属性无效! |
| s | 当档案设定了 s 参数时,他将会被完全的移除出这个硬盘空间。 |
| u | 与 s 相反的,当使用 u 来设定档案时,则数据内容其实还存在磁盘中,可以使用来 undeletion. |
常用命令
[root@1-1 ~]# lsattr /tmp/001.txt----ia---------- /tmp/001.txtchattr [+-]ia <filename>e.g# 给某个文件加上禁止删除与修改的属性chattr +ia /tmp/001.txt# 给某个文件去掉禁止删除与修改的属性chattr -ia /tmp/001.txt
说明详情
CHATTR(1) General Commands Manual CHATTR(1)NAMEchattr - change file attributes on a Linux file systemSYNOPSISchattr [ -RVf ] [ -v version ] [ mode ] files...DESCRIPTIONchattr changes the file attributes on a Linux file system.The format of a symbolic mode is +-=[aAcCdDeijsStTu].The operator '+' causes the selected attributes to be added to the existing attributes of the files; '-'causes them to be removed; and '=' causes them to be the only attributes that the files have.The letters 'aAcCdDeijsStTu' select the new attributes for the files: append only (a), no atime updates (A),compressed (c), no copy on write (C), no dump (d), synchronous directory updates (D), extent format (e),immutable (i), data journalling (j), secure deletion (s), synchronous updates (S), no tail-merging (t), topof directory hierarchy (T), and undeletable (u).The following attributes are read-only, and may be listed by lsattr(1) but not modified by chattr: compres‐sion error (E), huge file (h), indexed directory (I), inline data (N), compression raw access (X), and com‐pressed dirty file (Z).Not all flags are supported or utilized by all filesystems; refer to filesystem-specific man pages such asbtrfs(5), ext4(5), and xfs(5) for more filesystem-specific details.OPTIONS-R Recursively change attributes of directories and their contents.-V Be verbose with chattr's output and print the program version.-f Suppress most error messages.-v versionSet the file's version/generation number.ATTRIBUTESA file with the 'a' attribute set can only be open in append mode for writing. Only the superuser or aprocess possessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute.When a file with the 'A' attribute set is accessed, its atime record is not modified. This avoids a certainamount of disk I/O for laptop systems.A file with the 'c' attribute set is automatically compressed on the disk by the kernel. A read from thisfile returns uncompressed data. A write to this file compresses data before storing them on the disk. Note:please make sure to read the bugs and limitations section at the end of this document.A file with the 'C' attribute set will not be subject to copy-on-write updates. This flag is only supportedon file systems which perform copy-on-write. (Note: For btrfs, the 'C' flag should be set on new or emptyfiles. If it is set on a file which already has data blocks, it is undefined when the blocks assigned to thefile will be fully stable. If the 'C' flag is set on a directory, it will have no effect on the directory,but new files created in that directory will the No_COW attribute.)A file with the 'd' attribute set is not candidate for backup when the dump(8) program is run.When a directory with the 'D' attribute set is modified, the changes are written synchronously on the disk;this is equivalent to the 'dirsync' mount option applied to a subset of the files.The 'e' attribute indicates that the file is using extents for mapping the blocks on disk. It may not beremoved using chattr(1).The 'E' attribute is used by the experimental compression patches to indicate that a compressed file has acompression error. It may not be set or reset using chattr(1), although it can be displayed by lsattr(1).The 'h' attribute indicates the file is storing its blocks in units of the filesystem blocksize instead of inunits of sectors, and means that the file is (or at one time was) larger than 2TB. It may not be set orreset using chattr(1), although it can be displayed by lsattr(1).A file with the 'i' attribute cannot be modified: it cannot be deleted or renamed, no link can be created tothis file and no data can be written to the file. Only the superuser or a process possessing theCAP_LINUX_IMMUTABLE capability can set or clear this attribute.The 'I' attribute is used by the htree code to indicate that a directory is being indexed using hashed trees.It may not be set or reset using chattr(1), although it can be displayed by lsattr(1).A file with the 'j' attribute has all of its data written to the ext3 or ext4 journal before being written tothe file itself, if the filesystem is mounted with the "data=ordered" or "data=writeback" options. When thefilesystem is mounted with the "data=journal" option all file data is already journalled and this attributehas no effect. Only the superuser or a process possessing the CAP_SYS_RESOURCE capability can set or clearthis attribute.A file with the 'N' attribute set indicates that the file has data stored inline, within the inode itself. Itmay not be set or reset using chattr(1), although it can be displayed by lsattr(1).When a file with the 's' attribute set is deleted, its blocks are zeroed and written back to the disk. Note:please make sure to read the bugs and limitations section at the end of this document.When a file with the 'S' attribute set is modified, the changes are written synchronously on the disk; thisis equivalent to the 'sync' mount option applied to a subset of the files.A file with the 't' attribute will not have a partial block fragment at the end of the file merged with otherfiles (for those filesystems which support tail-merging). This is necessary for applications such as LILOwhich read the filesystem directly, and which don't understand tail-merged files. Note: As of this writing,the ext2 or ext3 filesystems do not (yet, except in very experimental patches) support tail-merging.A directory with the 'T' attribute will be deemed to be the top of directory hierarchies for the purposes ofthe Orlov block allocator. This is a hint to the block allocator used by ext3 and ext4 that the subdirecto‐ries under this directory are not related, and thus should be spread apart for allocation purposes. Forexample it is a very good idea to set the 'T' attribute on the /home directory, so that /home/john and/home/mary are placed into separate block groups. For directories where this attribute is not set, the Orlovblock allocator will try to group subdirectories closer together where possible.When a file with the 'u' attribute set is deleted, its contents are saved. This allows the user to ask forits undeletion. Note: please make sure to read the bugs and limitations section at the end of this document.The 'X' attribute is used by the experimental compression patches to indicate that the raw contents of a com‐pressed file can be accessed directly. It currently may not be set or reset using chattr(1), although it canbe displayed by lsattr(1).The 'Z' attribute is used by the experimental compression patches to indicate a compressed file is dirty. Itmay not be set or reset using chattr(1), although it can be displayed by lsattr(1).AUTHORchattr was written by Remy Card <Remy.Card@linux.org>. It is currently being maintained by Theodore Ts'o<tytso@alum.mit.edu>.BUGS AND LIMITATIONSThe 'c', 's', and 'u' attributes are not honored by the ext2, ext3, and ext4 filesystems as implemented inthe current mainline Linux kernels.The 'j' option is only useful if the filesystem is mounted as ext3 or ext4.The 'D' option is only useful on Linux kernel 2.5.19 and later.AVAILABILITYchattr is part of the e2fsprogs package and is available from http://e2fsprogs.sourceforge.net.SEE ALSOlsattr(1), btrfs(5), ext4(5), xfs(5).E2fsprogs version 1.42.9 December 2013 CHATTR(1)
