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.

Easy Create Laravel Project with Composer

Requirement Laravel, a popular PHP framework, is renowned for its elegant syntax and robust features, making it a top choice for web developers. One...
habibzain
1 min read

Virtualbox Change Storage Size

Changing the storage size of a virtual machine in VirtualBox involves a few steps. Here’s a general guide. Backup your Virtual Machine (VM) Before...
habibzain
35 sec read

Easy Setup Logrotate Nginx Ubuntu

Log rotation is an important aspect of managing log files on a Linux system, including those generated by Nginx. Logrotate is a utility that...
habibzain
1 min read

Leave a Reply

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

Never miss good article from us, get weekly updates in your inbox