Protect files from `rm -f`

permissionsrm

Much to my immediate chagrin, removing write permission from a file does not seem to protect it from rm -f:

touch foo
chmod a-w foo
rm -f foo

How can I protect a file from accidental deletion when rm will be called with the -f flag? It looks like chattr +i foo would work, but it requires root on my system (is that intended?), so I'm looking for a non-root solution.

Best Answer

To prevent files from being added or deleted to a directory, you can to remove the write permission for the directory.

Related Question