Chattr – A Linux Command – command is useful to change file attributes on Linux second extended file system. It provides more security on your files from unwanted changes and deletes. There are many attributes available to do it.
To Add attributes on a file we use plus (+) and to remove attributes use minus(-) sign . Some impotent attributes are [ASacDdIijsTtu].
How to Use Chattr Command
Add Attribute on File
Create a new file to test this. As example I have crate a new file tecadmin.txt using touch command and assigned 777 permission on file.
# touch tecadmin.txt # chmod 777 tecadmin.txt # ls -l tecadmin.txt -rwxrwxrwx 1 root root 0 Apr 10 13:10 tecadmin.txt
i attribute on file
# chattr +i tecadmin.txt
As you have enabled
i attribute on file, let’s try to remove this file, you we get following error, even file has 777 permissions.
# rm -f tecadmin.txt rm: cannot remove `tecadmin.txt': Operation not permitted
List Attributes of File
To List attributes on a file use
lsattr command specified with file name.
# lsattr tecadmin.txt ----i-------- tecadmin.txt
Remove Attributes of File
To clear attribute on a file just use (-) sign with attached attributes. for example in tecadmin.txt.
# chattr -i tecadmin.txt # lsattr tecadmin.txt ------------- tecadmin.txt
Attributes List in Chattr Command
Attribute [ i ]: A file with
i attribute cannot be modified, it cannot be deleted or renamed by any user included root. Only root can clear this attribute. By this attribute you can keep safe your impotent files from other users or accidental delete.