10.6. File attributes

The same way that FAT has file attributes (archive, system file, invisible), ext2fs has its own, but they are different. We speak of them here for the sake of completeness, but they are very seldom used. However, if you really want a secure system, read on.

There are two commands for manipulating file attributes: man 1 lsattr and man 1 chattr. You'll probably have guessed it, lsattr LiSts attributes, whereas chattr CHanges them. These attributes can only be set on directories and regular files. The following attributes are possible:

  1. A (no Access time) If a file or directory has this attribute set, whenever it is accessed, either for reading of for writing, its last access time will not be updated. This can be useful, for example, on files or directories which are very often accessed for reading, especially since this parameter is the only one which changes on an inode when it's open readonly.

  2. a (append only) If a file has this attribute set and is open for writing, the only operation possible will be to append data to its previous contents. For a directory, this means that you can only add files to it, but not rename or delete any existing file. Only root can set or clear this attribute.

  3. d (no dump) dump (8) is the standard Unix utility for backups. It dumps any filesystem for which the dump counter is 1 in /etc/fstab (see chapter "Filesystems and mount points"). But if a file or directory has this attribute set, unlike others, it will not be taken into account when a dump is in progress. Note that for directories, this also includes all subdirectories and files under it.

  4. i (immutable) A file or directory with this attribute set simply cannot be modified at all: it cannot be renamed, no further link can be created to it[1] and it cannot be removed. Only root can set or clear this attribute. Note that this also prevents changes to access time, therefore you don't need to set the A attribute when this one is set.

  5. s (secure deletion) When such a file or directory with this attribute set is deleted, the blocks it was occupying on disk are written back with zeros.

  6. S (Synchronous mode) When a file or directory has this attribute set, all modifications on it are synchronous and written back to disk immediately.

You may want, for example, to set the 'i' attribute on essential system files in order to avoid bad surprises. Also consider the 'A' attribute on man pages for example: this prevents a lot of disk operations and, in particular, it saves some battery life on laptops.

Notes

[1]

Be sure to understand what "adding a link" means both for a file and a directory :-)


Tux on Star from MandrakeSoft Linux is a registered trademark of Linus Torvalds. All other trademarks and copyrights are the property of their respective owners.
Unless otherwise stated, all the content of these pages and all images are Copyright MandrakeSoft S.A. and MandrakeSoft Inc. 2000.
http://www.linux-mandrake.com/