chattr
Quick Reference
Command Name:
chattr
Category:
file attributes
Platform:
linux
Basic Usage:
Common Use Cases
Syntax
chattr [OPTION]... [+-=][ATTRIBUTES]... FILE...
Options
Option | Description |
---|---|
-R, --recursive | Recursively change attributes of directories and their contents |
-V, --version | Display version information and exit |
-f, --silent, --quiet | Suppress most error messages |
-v, --verbose | Output a diagnostic for every file processed |
--help | Display help and exit |
--inode X | Only affect files with inode number X |
Available Attributes:
Attribute | Description |
---|---|
a | append only - file can only be opened in append mode for writing |
A | no atime updates - do not update atime (access time) when file is accessed |
c | compressed - file is compressed on the fly by the kernel |
C | no copy on write - file is not subject to copy-on-write updates (for filesystems like Btrfs) |
d | no dump - file is not candidate for backup with dump utility |
D | synchronous directory updates - directory updates are done synchronously |
e | extent format - file uses extents for mapping blocks on disk |
i | immutable - file cannot be modified, deleted, renamed, or linked |
j | data journaling - file data is journaled |
P | project hierarchy - inherit project ID from parent directory |
s | secure deletion - file is securely deleted (zeros written over data) |
S | synchronous updates - file changes are written synchronously to disk |
t | no tail-merging - file with this attribute will not have tail of partial blocks merged |
T | top of directory hierarchy - directory is the top of the directory hierarchy |
u | undeletable - file contents are saved when deleted (allows recovery) |
Examples
How to Use These Examples
The examples below show common ways to use the chattr
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
# Make a file immutable (can't be modified, deleted, or renamed) chattr +i important_file.txt
Advanced Examples:
# Set multiple attributes at once (immutable and append-only) chattr +ia critical_log.txt