chattr command – Change Attributes of a File in linux

chattr :

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.

Syntax :

 #chattr [operator] [switch] [file name]

Operator :

  • +   Add attribute.
  • -    Remove attribute.
  • =   Assign attributes (removing unspecified attributes)

Switch :

  •  -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.

Example 1:

chattr-with-i-option

Example:2

chattr-command

Main difference between a and i switch is in ‘i’ you cannot append the file while in ‘a’ switch you can append the file.

Example 3:

chattr-options

Leave a Reply

Your email address will not be published. Required fields are marked *