What' the differences between `chattr +i FILE` and `chmod -w FILE`? What' the differences between `chattr +i FILE` and `chmod -w FILE`? unix unix

What' the differences between `chattr +i FILE` and `chmod -w FILE`?


chattr +i sets the immutable filesystem attribute on the file. It differs from access control rules. Access control rules apply to the file attributes, while immutable is a filesystem extended file attribute, which may not be available on all filesystems. Only a user with root privileges can set or unset this extended attribute. Nobody, not even the owner or a user with write permission, can write into such file. A user without write file permission can create a hard link to a regular file, but if the file is marked as immutable, a user cannot create a hard link, since the filesystem cannot change the references count to this immutable file.

chattr +i is useful for protection from accidental deletion by root. Also an immutable file cannot be renamed or moved from one directory to another.


From chattr man page

A file with the 'i' attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file and no data can be written to the file. Only the superuser or a process possessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute.

As you can see , chattr is more powerful than chmod. chmod -w removes only 'write' permission to the file content. And also you need to use chattr +i to protect/lock the file then chattr -i to unlock


chmod -w file is available on all UNIX environment, however chattr -i FILE using extended file attributes might not be available on your system, depending on the type of the File System/Distro!

Apart from that, have a look at this link for the good and bad points of employing extended file attributes.