Linux chattr command

Linux chattr command

 Linux chattr command

The chattr command changes file attributes on a Linux file system. It provides a higher level of security on files and directories. You can also use this security to prevent important files from accidental deletion.


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

You can add any attribute to the file using the + symbol or use the – symbol to remove the attribute from the file.

Make File/Directory immutable

Use the +i option with chattr on file to make the file unchangeable, This will not allow making any changes in the file even to the root user.

$ chattr +i testfile.txt
$ chattr +i testdir

Enable Append Mode Only

Use the +a option to set the file to append mode only. You can not option this for editing. We can only append content to the file.

$ chattr +a myfile.txt

Remove Attributes

You can use – option with attribute to remove it from files. Use -R to run command recursively on the directory as well.

$ chattr -i testfile.txt
$ chattr -a myfile.txt
$ chattr -R -ai testdir

Post a Comment