[Linux]Managing file attributes on ext2
lsattr - chattr
Introduction
The Second Extended Filesystem (ext2) and the Third Extended Filesystem (ext3) contains file attributes that are less known, but still very practical.
To view or set these attributes, we have these two commands (in e2fsprogs),lsattr and chattr.
Isattr
To list the attributes.
How to use:
lsattr [files ...] [Dir...]
Displays the files given attributes, files, folders given files from the current folder.
lsattr-d [dir ...]
Displays attributes records given or current folder rather than their content.
lsattr-a
List attributes of all files.
lsattr-R dir
Recursively list the attributes of files.
chattr
Allows you to fix attributes.
How to use:
chattr +attr file
chattr -attr file
chattr =attr file
On the same operating principle as chmod
+attr adds the attribute
-attr remove attribute
=attr leaves only the attributes given
The -R option allows you to change the attributes recursively.
Attributes List
-A
The date of last access is not updated (only useful for reducing disk access on laptops)
-S
The file is synchronous, the records in the file are made immediately on the disc. (equivalent to the sync option of mount appliquée a subset of files)
-a
The file can be opened in addition to writing (log files, etc.)
Only redirection>> can be used, the file can not be deleted.
Only the root user or a program with the necessary rights can change this attribute.
-c
The file is automatically compressed before writing to disk, and unpacked before playback.
-D
The case is synchronous (see:-S) (equivalent to option dirsync mount on a subset of records)
Usable from the kernel 2.5.19
-d
The file will not be saved by the dump
-I
Can not be fixed by chattr only listed by lsattr
Indicates that the file is indexed.
-i
The file / directory can not be amended, deleted, renamed or linked symbolically, not even by root.
Only root or a binary with the necessary rights can set this attribute.
-j
EXT3 only.
If the file system is mounted with "data = ordered" or "data = writeback", all data files are written to the log before being written to the file itself.
If the file system is mounted with "data = journal", all data files are all already in the newspaper, the attribute has no effect.
Only root or a binary with the necessary rights can set this attribute.
-s
When the file is destroyed, all data blocks are being released to zero.
-T
Usable from version 2.5.46 kernel.
-t
Concern fragmentation.
This is currently not implemented on the ext2 and ext3 to my knowledge.
-u
If the file is deleted, its content is saved, it allows the user to seek its restoration.
-E
Experimental, can detect an error of compression can not be fixed by chattr, but can be listed by lsattr
-X
Experimental shows that the raw data to a compressed file can be accessed directly.
Can not yet be set by chattr
-Z
Experimental, provides information on the status of a compressed file.
can only be listed by lsattr
A c s u attributes can only be used from a 2.3 kernel, but are not implemented in 2.4 kernels, it seems to be the case in the 2.6 kernels.
In any case, better check out the functions of an Attribute before using it.