habibzain Just husband, father and enthusiastic men about System Administration. Love to write short article about it. Perhaps can help and be useful for others.

chattr Make File or folder Immutable

1 min read

Make-File-or-Directory-Immutable

Hi Dude, sometime we want lock a file or folder from overwritten because any update or others. Simple method is setting the immutable flag on a file or folder will prevent any changes to it. For folders, this means that no files or foldes may be added to or removed from the immutable folder. However, file and folder in the immutable with chattr can’t be modified.

File or Folder Immutable

Making Files in Linux Immutable with the “chattr” Command. The chattr command in linux is used to change the attributes of files on linux to avoid incidents of wrong deletion, or prevent important files and directories on the system from being changed. Chattr itself also applies to all users, including users with root privileges though.

For linux user, simple method create file or folder immutable is using command "chattr" with the “+i” flag.

chattr +i /path/to/file

With "chattr" above, the file is immutable. If any update or anything the file is not change.

And then, how to vice versa? Can I make a file or directory no longer immutable?

No Longer Immutable

Here is simple way. To change a file or folder so that it is no longer immutable, use the “chattr” command with the “-i” flag. Here is an example:

chattr -i /PATH/TO/FILE/DIRECTORY

If we want other parameter, please read more about chattr can use manual command.

man chattr

lsattr to Show List Attribute

And then, what is different if the file set with chattr?

Here is example. Attribute file before receiving immutable.

[root@srv habibza]# lsattr remove.txt
-------------e- remove.txt

After given command chattr +i, there is a flag "i" in lsattr.

[root@ns3 habibza]# chattr +i remove.txt
[root@ns3 habibza]# lsattr remove.txt
----i--------e- remove.txt

That is short article about chattr. May be it’s helpful, please feel free to leave a comment if you have any questions and I’ll appreciate it.

habibzain Just husband, father and enthusiastic men about System Administration. Love to write short article about it. Perhaps can help and be useful for others.

Ispconfig Nginx Directives Laravel

In a typical Laravel installation, the public folder contains all of the publicly accessible files for the application. This includes the index.php file, which...
habibzain
47 sec read

How to Hide Version nginx

Nginx is a popular web server that powers many websites and applications. However, by default, nginx reveals its version number in the HTTP response...
habibzain
1 min read

How to Install SSH in Windows 10/11

SSH (Secure Shell) is a protocol that allows us to securely remote servers and devices over a network. SSH can be used for various...
habibzain
1 min read

Leave a Reply

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

Never miss a story from us, get weekly updates in your inbox