chattr — Change Linux File Attributes

chattr changes extended file attributes on Linux filesystems. It is most often seen with the immutable attribute, which can protect a file from being modified or deleted.

Make a file immutable

sudo chattr +i filename

After this, even the root user cannot edit or delete the file normally until the attribute is removed.

Remove the immutable attribute

sudo chattr -i filename

Check current attributes

lsattr filename

Use this carefully. Immutable files are useful for protecting important configuration files, but they can also confuse troubleshooting if the setting is forgotten.

Leave a Comment