How to prevent accidental deletion of file in Linux

Linux

It is unavoidable that some important files such as configuration files undesirably get overwritten or deleted during system upgrades. In Linux you can use the chattr command to set file attributes just like Windows’ attr command.

By setting the file as immutable, any user including super-user cannot write or delete the file but they can read it. Below is an example on how to set an immutable file attribute.

shell# chattr +i myfile.conf

to unset the immutable attribute the command is

shell# chattr -i myfile.com

Other attributes include:

append only (a)
compressed (c)
don’t update atime (A)
synchronous directory updates (D)
synchronous updates (S)
data journalling (j)
no dump (d)
top of directory hierarchy (T)
no tail-merging (t)
secure deletion (s)
undeletable (u)
immutable (i)


Permalink • Print • Comment

Trackback uri

http://seoroot.com/blog/howto/how-to-prevent-accidental-deletion-of-file-in-linux.html/trackback

Related Entries

Leave a Comment