How to Make File and directory undeletable in Linux

How to Make File and directory undeletable in Linux

A Linux system administrator needs to know some Linux tricks. In this article, you will learn how to Make File and directory undeletable Linux (Even By Root).

As you know, root is the account or user name that by default can modify all directories and files on a system, on Unix-like operating systems including Linux.

In this tutorial, you will see how to make directories or files unremovable even by the root user in Linux.



How to Make File and directory undeletable Linux

Among the Linux tips, learning to make files and directories undeletable would be so useful for you, as you can apply this tip on all important configuration files so that no one accidentally or intentionally deletes it.

To make files unmodifiable, you can use the following command which makes /backups/passwd file immutable (or undeletable). After that, you will not be able to create a link to it and no data can be written to the file.

Also, please be aware that to set or remove this attribute, you need superuser privileges. So use sudo commands.

sudo chattr +i /backups/passwd  OR  sudo chattr +i -V /backups/passwd

Also, use the lsattr command, to view attributes of a file

$ lsattr /backups/passwd   

Now let’s try to remove the immutable file, both as a normal user and as a root.

rm /backups/passwd  sudo rm /backups/passwd    

Buy Linux Virtual Private Server

Recommended Article: How To Install Yarn On CentOS 7

How to recursively make directory undeletable in Linux

Here we have the -R flag, to recursively change attributes of directories and their contents.

$ sudo chattr +i -RV /backups/

Then, use -i sign to remove the above attribute and making a file mutable again.

sudo chattr -i /backups/ passwd


Good job! Now you know how to make File and directory undetectable, even by root in Linux.


Dear user, we hope you would enjoy this tutorial, you can ask questions about this training in the comments section, or to solve other problems in the field of Eldernode training, refer to the Ask page section and raise your problems in it.

How useful was this post?

Click on a star to rate it!

Average rating 3 / 5. Vote count: 2

No votes so far! Be the first to rate this post.

View More Posts
Marilyn Bisson
Content Writer
Eldernode Writer
We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

Leave a Reply

Your email address will not be published. Required fields are marked *

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way


7 days a week, 24 hours a day