How to make a file or a folder undeletable in Ubuntu

Here is an easy way to make a file or a folder undeletable even by root user in Ubuntu.

Making a folder undeletable

To make a folder undeletable run:

sudo chattr +i -R foldername

After that you can't delete, rename or do anything with this folder.
But if you don't need this folder anymore or you've got to apply some changes to it run:

sudo chattr -i -R foldername

Making a file undeletable

To make a file undeletable run:

sudo chattr +i filename

To be able to change or delete the file run:

sudo chattr -i filename

  1. Echy
    2012-10-16 22:00:34
    If there are too many files, you can have an error message like "argument list too long" or other thing like that. So you can use |xargs for delete all files. Like
    ls . |xargs -l rm -f
    (in the directory need to be cleaned)

Got a comment?

captcha =


  1. System (20)
    1. FreeBSD (5)
    2. Linux (9)
  2. Email (2)
  3. DNS (2)
  4. Databases (1)
  5. WebServer (27)
Copyright © 2024 HowToUnix - *nix Howtos and Tutorials
All Rights Reserved.