twitter
Categories:- Unix Commands

How to Change the Attributes of a File in Linux using chattr Command

 

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:

 

 

Example 2 :

 

 

 

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:

 

RoseHosting.com on, 2013-05-19 09:00:56
hi, thanks for posting this. I wanted to follow up that 'chattr' should be available in other file systems such as ReiserFS, XFS, JFS etc.. ( http://en.wikipedia.org/wiki/Chattr ) for ReiserFS, one may need to mount the FS with the 'attrs' flag
PRASHANT on, 2013-11-30 05:02:51
VERY NICE QUIZ IN IT RELATED..
Post Your Comments
Name:
Email:
Comment:
Security Code  *
Enter Security Code  *
Can't read the image? click here to refresh