Home

chattr

chattr is a Linux command used to change file attributes on filesystems that support extended attributes, most commonly ext2, ext3, and ext4. File attributes are special flags stored in inodes that can modify how the system handles a file beyond standard permissions. chattr can set or clear these attributes, and the effects depend on the attribute and the filesystem.

Two attributes are commonly discussed. The immutable attribute, i, makes a file unmodifiable, undeletable, and unrenamable

Usage is straightforward. The syntax is chattr [operator][attribute] file[...], where operator is + to set, - to clear,

Limitations include that not all filesystems support chattr, and attributes are specific to the filesystem type

under
normal
circumstances;
even
a
regular
user
cannot
alter
or
remove
the
file
until
the
attribute
is
cleared.
The
append-only
attribute,
a,
restricts
writes
to
only
appending
data
to
the
end
of
the
file;
existing
content
and
the
file’s
metadata
cannot
be
modified
except
by
appending.
Other
attributes
may
exist
on
some
filesystems,
such
as
compressed
or
no-dump
flags,
but
the
availability
and
meaning
of
attributes
vary
by
filesystem
and
kernel
version.
For
precise
behavior,
refer
to
the
system’s
man
page
for
chattr
and
the
lsattr
utility
for
listing
attributes.
or
=
to
assign
explicitly.
For
example,
chattr
+i
important.txt
sets
the
immutable
flag,
and
chattr
-i
important.txt
clears
it.
The
-R
option
applies
changes
recursively
to
directories.
To
view
current
attributes,
use
lsattr
file.
and
kernel.
Certain
attributes
may
require
elevated
privileges
to
modify.