chattr
Permissions
Usage
sudo chattr +i [file]Sets filesystem-level attributes such as immutable; with +i even root must clear the flag before editing, and it works only on Linux filesystems like ext4, xfs and btrfs.
Common flags
| Flag | Meaning |
|---|---|
| +i | Immutable: not even root may change or delete it until -i |
| -i | Clear the immutable flag so the file can be edited again |
| +a | Append only, which suits a log file |
| +A | Do not update the access time on reads |
| -R | Apply through a whole tree |
| lsattr | The companion command that shows which flags are set |
Examples
sudo chattr +i /etc/resolv.confStops anything from overwriting the file.
lsattr /etc/resolv.confShows the i in the flag list.
sudo chattr -i /etc/resolv.confRemoves it again so you can edit.
Numeric and symbolic modes name the same thing: 755 and u=rwx,go=rx are the same permission.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does chattr do?
Sets filesystem-level attributes such as immutable; with +i even root must clear the flag before editing, and it works only on Linux filesystems like ext4, xfs and btrfs.
Q. How do I type it?
sudo chattr +i [file] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
6 are listed here; the full set is in man chattr. This command sits under Permissions.
Related commands
man page: man chattr