File attributes
chattr – (Change Attribute) is a command line Linux utility that is used to set/unset certain attributes to a file in Linux system to secure accidental deletion or modification of important files and folders, even though you are logged in as a root user.
lsattr – list file attributes on a Linux second extended file system
By default, file attributes are not preserved by cp, rsync, and other similar programs.
For ext2 and ext3 file systems, the e2fsprogs package contains the programs lsattr and chattr that list and change a file’s attributes, respectively. Though some are not honored by all file systems, the available attributes are:
a: append only
c: compressed
d: no dump
e: extent format
i: immutable
j: data journalling
s: secure deletion
t: no tail-merging
u: undeletable
A: no atime updates
C: no copy on write
D: synchronous directory updates
S: synchronous updates
T: top of directory hierarchy
For example, a file is set with “i” attribute, cannot be modified (immutable). Means no renaming, no symbolic link creation, no execution, no writable, only superuser can unset the attribute.
root# chattr +i /path/to/file
A file is set with “a” attribute, can only be open in append mode for writing.
root# chatt +a /path/to/file
To remove an attribute on a file just change + to -.
To list the file atributes, use the lsattr command:
root# lsattr /path/to/file
----ia---------- /path/to/file
root#