Linux - Is there a way to prevent/protect a file from being deleted even by root?

I have a very important file which an application in my workplace uses, i need to make sure it is not delete whatsoever, how can I do that?


Solution 1:

Yes, you can change the attributes of the file to read-only.

The command is:

chattr +i filename

And to disable it:

chattr -i filename

From man chattr:

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 or a process possessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute.

Solution 2:

Burn it to a CD. Put the CD in a CD-ROM drive and access it from there.