Hi guys,
In this post I will discuss about command to stop accidentally delete of files and folder in Linux.
chattr command : -
chattr attribute is used to stop accidentally delete of files and folder. You cannot delete the files secured via chattr attribute even though you have full permission over files.
Syntax for chattr commandThe 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.
-R
Recursively change attributes of directories and their contents.
-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 :-To add chattr run below command.
Quote#chattr +aui /root/impfiles.conf
To remove chattr run command as below.
Quote#chattr -aui /root/impfiles.conf
Hope this post help you.
Enjoy !!!