Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I make some file impossible to be deleted by user even if it is under his/her home folder?

share|improve this question
up vote 12 down vote accepted

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:

  1. you have to be root to change attributes;
  2. 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.
share|improve this answer
Worked perfectly! Thank you so much. – desgua Apr 5 '11 at 14:43
Is there a way to use this and maintain other permissions? For example, still allowing the user and group permissions for rwx of sub-directories and files. – roydukkey Apr 8 '14 at 18:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.