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.

Centos Failed Update Kernel

Today I did a kernel update on my server with Centos 7 OS. At the end of the update process, I found a kernel...
habibzain
1 min read

Easy Fix Missing mirrorlist http://mirrorlist.centos.org on CentOS 7

When running yum update or command that utilize the yum system, errors similar to the following are produced: If you’re encountering issues with the...
habibzain
1 min read

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

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