lsattr

查看文件的隐藏属性

如何安装

  1. # centos7-2
  2. # yum 源安装
  3. yum -y install e2fsprogs

常用命令

  1. # 查看某个文件夹下文件的隐藏属性
  2. lsattr <dir>
  3. ##########################
  4. # 说明: 一般文件么有任何说明 #
  5. ##########################
  6. e.g
  7. [root@1-1 ~]# lsattr /tmp
  8. ----ia---------- /tmp/001.txt
  9. ---------------- /tmp/lsattr.txt
  10. ---------------- /tmp/chattr.txt
  11. # 查看某个文件夹下所有文件的隐藏属性
  12. lsattr -a <dir>
  13. e.g
  14. [root@1-1 ~]# lsattr -a /tmp
  15. ---------------- /tmp/.
  16. ---------------- /tmp/..
  17. ---------------- /tmp/.Test-unix
  18. ---------------- /tmp/.XIM-unix
  19. ---------------- /tmp/.ICE-unix
  20. # 查看某个文件的隐藏属性
  21. lsattr <filename>
  22. e.g
  23. [root@1-1 ~]# lsattr /tmp/001.txt
  24. ----ia---------- /tmp/001.txt
  25. e.g
  26. # 查看某个文件夹下所有文件及子目录的所有隐藏属性
  27. [root@1-1 ~]# lsattr -aR /tmp
  28. ---------------- /tmp/.
  29. ---------------- /tmp/..
  30. ---------------- /tmp/.Test-unix
  31. /tmp/.Test-unix:
  32. ---------------- /tmp/.Test-unix/.
  33. ---------------- /tmp/.Test-unix/..
  34. ---------------- /tmp/.XIM-unix
  35. ----ia---------- /tmp/001.txt

说明详情

  1. LSATTR(1) General Commands Manual LSATTR(1)
  2. NAME
  3. lsattr - list file attributes on a Linux second extended file system
  4. SYNOPSIS
  5. lsattr [ -RVadv ] [ files... ]
  6. DESCRIPTION
  7. lsattr lists the file attributes on a second extended file system. See chattr(1) for a description of the
  8. attributes and what they mean.
  9. OPTIONS
  10. -R Recursively list attributes of directories and their contents.
  11. -V Display the program version.
  12. -a List all files in directories, including files that start with `.'.
  13. -d List directories like other files, rather than listing their contents.
  14. -v List the file's version/generation number.
  15. AUTHOR
  16. lsattr was written by Remy Card <Remy.Card@linux.org>. It is currently being maintained by Theodore Ts'o
  17. <tytso@alum.mit.edu>.
  18. BUGS
  19. There are none :-).
  20. AVAILABILITY
  21. lsattr is part of the e2fsprogs package and is available from http://e2fsprogs.sourceforge.net.
  22. SEE ALSO
  23. chattr(1)
  24. 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.

常用命令

  1. [root@1-1 ~]# lsattr /tmp/001.txt
  2. ----ia---------- /tmp/001.txt
  3. chattr [+-]ia <filename>
  4. e.g
  5. # 给某个文件加上禁止删除与修改的属性
  6. chattr +ia /tmp/001.txt
  7. # 给某个文件去掉禁止删除与修改的属性
  8. chattr -ia /tmp/001.txt

说明详情

  1. CHATTR(1) General Commands Manual CHATTR(1)
  2. NAME
  3. chattr - change file attributes on a Linux file system
  4. SYNOPSIS
  5. chattr [ -RVf ] [ -v version ] [ mode ] files...
  6. DESCRIPTION
  7. chattr changes the file attributes on a Linux file system.
  8. The format of a symbolic mode is +-=[aAcCdDeijsStTu].
  9. The operator '+' causes the selected attributes to be added to the existing attributes of the files; '-'
  10. causes them to be removed; and '=' causes them to be the only attributes that the files have.
  11. The letters 'aAcCdDeijsStTu' select the new attributes for the files: append only (a), no atime updates (A),
  12. compressed (c), no copy on write (C), no dump (d), synchronous directory updates (D), extent format (e),
  13. immutable (i), data journalling (j), secure deletion (s), synchronous updates (S), no tail-merging (t), top
  14. of directory hierarchy (T), and undeletable (u).
  15. The following attributes are read-only, and may be listed by lsattr(1) but not modified by chattr: compres
  16. sion error (E), huge file (h), indexed directory (I), inline data (N), compression raw access (X), and com
  17. pressed dirty file (Z).
  18. Not all flags are supported or utilized by all filesystems; refer to filesystem-specific man pages such as
  19. btrfs(5), ext4(5), and xfs(5) for more filesystem-specific details.
  20. OPTIONS
  21. -R Recursively change attributes of directories and their contents.
  22. -V Be verbose with chattr's output and print the program version.
  23. -f Suppress most error messages.
  24. -v version
  25. Set the file's version/generation number.
  26. ATTRIBUTES
  27. A file with the 'a' attribute set can only be open in append mode for writing. Only the superuser or a
  28. process possessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute.
  29. When a file with the 'A' attribute set is accessed, its atime record is not modified. This avoids a certain
  30. amount of disk I/O for laptop systems.
  31. A file with the 'c' attribute set is automatically compressed on the disk by the kernel. A read from this
  32. file returns uncompressed data. A write to this file compresses data before storing them on the disk. Note:
  33. please make sure to read the bugs and limitations section at the end of this document.
  34. A file with the 'C' attribute set will not be subject to copy-on-write updates. This flag is only supported
  35. on file systems which perform copy-on-write. (Note: For btrfs, the 'C' flag should be set on new or empty
  36. files. If it is set on a file which already has data blocks, it is undefined when the blocks assigned to the
  37. file will be fully stable. If the 'C' flag is set on a directory, it will have no effect on the directory,
  38. but new files created in that directory will the No_COW attribute.)
  39. A file with the 'd' attribute set is not candidate for backup when the dump(8) program is run.
  40. When a directory with the 'D' attribute set is modified, the changes are written synchronously on the disk;
  41. this is equivalent to the 'dirsync' mount option applied to a subset of the files.
  42. The 'e' attribute indicates that the file is using extents for mapping the blocks on disk. It may not be
  43. removed using chattr(1).
  44. The 'E' attribute is used by the experimental compression patches to indicate that a compressed file has a
  45. compression error. It may not be set or reset using chattr(1), although it can be displayed by lsattr(1).
  46. The 'h' attribute indicates the file is storing its blocks in units of the filesystem blocksize instead of in
  47. units of sectors, and means that the file is (or at one time was) larger than 2TB. It may not be set or
  48. reset using chattr(1), although it can be displayed by lsattr(1).
  49. A file with the 'i' attribute cannot be modified: it cannot be deleted or renamed, no link can be created to
  50. this file and no data can be written to the file. Only the superuser or a process possessing the
  51. CAP_LINUX_IMMUTABLE capability can set or clear this attribute.
  52. The 'I' attribute is used by the htree code to indicate that a directory is being indexed using hashed trees.
  53. It may not be set or reset using chattr(1), although it can be displayed by lsattr(1).
  54. A file with the 'j' attribute has all of its data written to the ext3 or ext4 journal before being written to
  55. the file itself, if the filesystem is mounted with the "data=ordered" or "data=writeback" options. When the
  56. filesystem is mounted with the "data=journal" option all file data is already journalled and this attribute
  57. has no effect. Only the superuser or a process possessing the CAP_SYS_RESOURCE capability can set or clear
  58. this attribute.
  59. A file with the 'N' attribute set indicates that the file has data stored inline, within the inode itself. It
  60. may not be set or reset using chattr(1), although it can be displayed by lsattr(1).
  61. When a file with the 's' attribute set is deleted, its blocks are zeroed and written back to the disk. Note:
  62. please make sure to read the bugs and limitations section at the end of this document.
  63. When a file with the 'S' attribute set is modified, the changes are written synchronously on the disk; this
  64. is equivalent to the 'sync' mount option applied to a subset of the files.
  65. A file with the 't' attribute will not have a partial block fragment at the end of the file merged with other
  66. files (for those filesystems which support tail-merging). This is necessary for applications such as LILO
  67. which read the filesystem directly, and which don't understand tail-merged files. Note: As of this writing,
  68. the ext2 or ext3 filesystems do not (yet, except in very experimental patches) support tail-merging.
  69. A directory with the 'T' attribute will be deemed to be the top of directory hierarchies for the purposes of
  70. the Orlov block allocator. This is a hint to the block allocator used by ext3 and ext4 that the subdirecto‐
  71. ries under this directory are not related, and thus should be spread apart for allocation purposes. For
  72. example it is a very good idea to set the 'T' attribute on the /home directory, so that /home/john and
  73. /home/mary are placed into separate block groups. For directories where this attribute is not set, the Orlov
  74. block allocator will try to group subdirectories closer together where possible.
  75. When a file with the 'u' attribute set is deleted, its contents are saved. This allows the user to ask for
  76. its undeletion. Note: please make sure to read the bugs and limitations section at the end of this document.
  77. The 'X' attribute is used by the experimental compression patches to indicate that the raw contents of a com‐
  78. pressed file can be accessed directly. It currently may not be set or reset using chattr(1), although it can
  79. be displayed by lsattr(1).
  80. The 'Z' attribute is used by the experimental compression patches to indicate a compressed file is dirty. It
  81. may not be set or reset using chattr(1), although it can be displayed by lsattr(1).
  82. AUTHOR
  83. chattr was written by Remy Card <Remy.Card@linux.org>. It is currently being maintained by Theodore Ts'o
  84. <tytso@alum.mit.edu>.
  85. BUGS AND LIMITATIONS
  86. The 'c', 's', and 'u' attributes are not honored by the ext2, ext3, and ext4 filesystems as implemented in
  87. the current mainline Linux kernels.
  88. The 'j' option is only useful if the filesystem is mounted as ext3 or ext4.
  89. The 'D' option is only useful on Linux kernel 2.5.19 and later.
  90. AVAILABILITY
  91. chattr is part of the e2fsprogs package and is available from http://e2fsprogs.sourceforge.net.
  92. SEE ALSO
  93. lsattr(1), btrfs(5), ext4(5), xfs(5).
  94. E2fsprogs version 1.42.9 December 2013 CHATTR(1)