desgua Asked: 2011-04-05 17:22:52 +0800 CST2011-04-05 17:22:52 +0800 CST 2011-04-05 17:22:52 +0800 CST How to prevent a file under user folder to be deleted? 772 How can I make some file impossible to be deleted by user even if it is under his/her home folder? nautilus 1 Answers Voted Best Answer enzotib 2011-04-05T18:07:52+08:002011-04-05T18:07:52+08:00 It is possible to make a file impossible to delete, even from root, on an ext2/3/4 filesystem, changing a file system attribute of the file: $ cd $ touch dummy $ sudo chattr +i dummy $ rm dummy rm: remove write-protected regular empty file `dummy'? y rm: cannot remove `dummy': Operation not permitted $ sudo rm dummy [sudo] password for enzotib: rm: cannot remove `dummy': Operation not permitted $ More information on chattr and lsattr manual pages. If later you want to delete the file you should use sudo chattr -i dummy before using rm. There are two drawbacks to this: you have to be root to change attributes; you can forget about the attributes of that file or the way to change them, so that it seem you cannot delete the file anymore.
It is possible to make a file impossible to delete, even from root, on an ext2/3/4 filesystem, changing a file system attribute of the file:
More information on
chattr
andlsattr
manual pages.If later you want to delete the file you should use
before using
rm
.There are two drawbacks to this: