chattr command – Change Attributes of a File in linux
chattr is a command in the Linux operating system that allows a user to set certain attributes on a file residing on an ext2/ext3/ext4 based filesystem.
#chattr [operator] [switch] [file name]
- + Add attribute.
- – Remove attribute.
- = Assign attributes (removing unspecified attributes)
- -R Recursively change attributes of directories and their contents. Symbolic links encountered during recursive directory traversals are ignored.
- -a A file with the ‘a’ attribute set can only be open in append mode for writing. Only the superuser can set or clear this attribute.
- -i A file with the ‘i’ attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file and no data can be written to the file. Only the superuser can set or clear this attribute.
Main difference between a and i switch is in 'i' you cannot append the file while in 'a' switch you can append the file.