chattr - Unix, Linux Command


Advertisements

Previous Page
Next Page  
 

NAME

chattr change file attributes on a Linux file system

SYNOPSIS

chattr [ -RVf ] [ -v version ] [ mode ] files...

DESCRIPTION

chattr changes the file attributes on a Linux file system.

The format of a symbolic mode is +-=[acdeijstuACDST].

The operator `+' causes the selected attributes to be added to the existing attributes of the files; `-' causes them to be removed; and
`=' causes them to be the only attributes that the files have. The letters `acdeijstuACDST' select the new attributes for the files:
append only (a), compressed (c), no dump (d), extent format (e), immutable (i), data journalling (j), secure deletion (s), no tail-merg‐
ing (t), undeletable (u), no atime updates (A), no copy on write (C),synchronous directory updates (D), synchronous updates (S), and top of
directory hierarchy (T).

OPTIONS

TAG DESCRIPTION
-R Recursively change attributes of directories and their contents.
-V Be verbose with chattr's output and print the program version.
-f Suppress most error messages.
-v version Set the file's version/generation number.

EXAMPLES

EXAMPLE-1:

To add attributes on files to secure from deletion:

ls -l

-rw-rw-r-- 1 nubo nubo 106 Jan 7 19:44 system.bz2
-rw-rw-r-- 1 nubo nubo 46 Jan 7 20:37 xyz

$ sudo chattr +i xyz

$ sudo chattr +i system.bz2

or 

# chattr +i xyz

# chattr +i system.bz2

(Root level privillages required to run  this command)

 output:

$ rm -rf xyz

rm: cannot remove ‘xyz’: Operation not permitted

 

EXAMPLE-2:

To unset attributes on a file :

# chattr -i xyz
# chattr -i system.bz2

output:
# lsattr
---------------- ./xyz
---------------- ./system.bz2

(Now Rm -rf and chmod can be performed on these files)

 

EXAMPLE-3:

To Secure /etc/passwd and /etc/shadow files:

# chattr +i /etc/passwd
# chattr +i /etc/shadow

# useradd new user
useradd: cannot open /etc/passwd

 

EXAMPLE-4:

To Secure Directories:

# chattr -R +i Folder_important

# rm -rf Folder_important/ rm: cannot remove 'Folder_important/': Operation not permitted


EXAMPLE-5:

To recover a file after deletion:

 If  file is deleted, user can ask for undelete with

# chattr +u file_name 
 Note:
The `c', 's', and `u' attributes are not honored by the ext2, ext3,
and ext4 filesystems as implemented in the current mainline Linux ker‐
nels.

The `j' option is only useful if the filesystem is mounted as ext3.

The `D' option is only useful on Linux kernel 2.5.19 and later.



Previous Page
Next Page