Linux chattr command
The chattr command change 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 file using + symbol or use – symbol to remove the attribute from the file.
Make File/Directory immutable
Use +i option with chattr on file to make file unchangeable, This will not allow making any changes in the file even to root user.
$ chattr +i testfile.txt $ chattr +i testdir
Enable Append Mode Only
Use +a option to set the file to append mode only. You can not option this for editing. We can only append content to file.
$ chattr +a myfile.txt
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