How to stop accidentally delete of files and folder in Linux ?

Started by Dipak Bhoi, April 20, 2014, 09:14:30 AM

Previous topic - Next topic

Dipak Bhoi

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 command

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.

-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 !!!
MilesWeb - 30-Day Money Back
cPanel Web Hosting - cPanel Hosting in India
Grab a Free SSL for your website.  WordPress Optimized Solution.