Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

chattr changes filesystem-level inode attributes. For the two most common jobs, use sudo chattr +i file to make a file immutable, sudo chattr -i file to unlock it, sudo chattr +a file to allow appending only, and sudo chattr -a file to remove append-only status. Check the result with lsattr file. These flags are an additional local safeguard, not a replacement for permissions, encryption, backups, or remote logging.

What chattr changes

The name means “change attributes.” Unlike chmod, which changes Unix read, write, and execute permission bits, chattr changes filesystem-specific inode flags. The kernel and filesystem use those flags to impose behaviors such as immutability, append-only writes, synchronous updates, or no-atime updates.

chattr is most closely associated with ext2, ext3, and ext4, but some flags are also implemented by Btrfs, XFS, F2FS, and other filesystems. Support is not determined by Ubuntu alone: the Ubuntu release, kernel, e2fsprogs version, filesystem, mount options, and filesystem layer (such as overlay, FUSE, network, or container storage) all matter. Consult the local manual with man chattr before relying on a less common flag.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For current Ubuntu documentation, see the Resolute chattr manual and the kernel’s FS_IOC_SETFLAGS reference.

#1 Best Overall
Sale
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
  • Easily store and access 2TB to content on the go with the Seagate Portable Drive, a USB external hard drive
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
  • To get set up, connect the portable hard drive to a computer for automatic recognition no software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.

Check installation and the filesystem

Verify the commands

command -v chattr
chattr --version
lsattr --version

Ubuntu supplies both commands in the e2fsprogs package. If they are missing:

sudo apt update
sudo apt install e2fsprogs

Package versions vary by release. For example, the current Ubuntu Resolute page identifies e2fsprogs 1.47.2-3ubuntu4, while Noble documents a different package revision; do not treat either number as universal.

Identify the storage layer

findmnt -T /path/to/file -o TARGET,SOURCE,FSTYPE,OPTIONS
df -T /path/to/file

Run this before troubleshooting a flag. A command that works on ext4 may be unsupported or behave differently on Btrfs, XFS, a network share, an overlay mount, or a FUSE filesystem.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Seagate Portable 5TB External Hard Drive HDD – USB 3.0 for PC, Mac, PS4, & Xbox - 1-Year Rescue Service (STGX5000400), Black
  • Easily store and access 5TB of content on the go with the Seagate portable drive, a USB external hard Drive
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
  • To get set up, connect the portable hard drive to a computer for automatic recognition software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.

Understand chattr syntax

chattr [ -RVf ] [ -v version ] [ -p project ] [ mode ] files...

The mode starts with an operator:

  • + adds flags while preserving other modifiable flags.
  • - removes the specified flags.
  • = replaces the current modifiable flag set. Use it only when you intentionally want to clear other flags.
sudo chattr +i file
sudo chattr -i file
sudo chattr +ai logfile
sudo chattr -ai logfile

-R applies the operation recursively, -V prints verbose output, and -f suppresses most errors. Prefer + and - for routine administration; a command such as sudo chattr =i file can unintentionally remove another attribute.

Read attributes with lsattr

lsattr notes.txt

Example output:

----i---------e------- notes.txt
  • Each letter represents an enabled attribute.
  • A hyphen means that position has no enabled attribute.
  • The width and available letters vary by version and filesystem.
  • i is immutable and a is append-only.
  • e commonly indicates extent format. It is normally diagnostic rather than a flag you manually change.

For a directory’s own flags, use -d; without it, lsattr lists entries inside the directory.

lsattr -d config-directory
lsattr -R config-directory
stat notes.txt

Make a file immutable with +i

Use a disposable file for practice:

mkdir -p ~/chattr-demo
cd ~/chattr-demo
printf 'Do not edit this file.n' > protected.txt
sudo chattr +i protected.txt
lsattr protected.txt

The output should include i. While it is set, ordinary attempts to change contents or metadata, delete or rename the inode, or create a hard link to it fail with an operation-not-permitted-style error:

Rank #3
Seagate Portable 1TB External Hard Drive HDD – USB 3.0 for PC, Mac, PlayStation, & Xbox, 1-Year Rescue Service (STGX1000400) , Black
  • Easily store and access 1TB to content on the go with the Seagate Portable Drive, a USB external hard drive.Specific uses: Personal
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop. Reformatting may be required for Mac
  • To get set up, connect the portable hard drive to a computer for automatic recognition no software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.
echo "new text" >> protected.txt
rm protected.txt
mv protected.txt renamed.txt
chmod 600 protected.txt

The owner and ordinary applications are blocked, and root cannot perform those ordinary operations while the flag remains set. A sufficiently privileged administrator can still clear the flag, alter storage through other administrative means, replace the filesystem, or restore a copy. Treat +i as resistance to accidental changes and some local tampering, not as encryption or tamper-proof storage.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Unlock the file before maintenance:

sudo chattr -i protected.txt
lsattr protected.txt

Make a file append-only with +a

Append-only mode allows new data to be written at the end but blocks ordinary overwrites, truncation, deletion, and renaming of the protected inode.

sudo touch audit.log
sudo chattr +a audit.log
lsattr audit.log
echo 'event 1' >> audit.log
echo 'event 2' >> audit.log

These operations should fail while a is active:

echo 'overwrite' > audit.log
truncate -s 0 audit.log
rm audit.log

Clear the flag for rotation or repair:

sudo chattr -a audit.log

Append-only status often conflicts with logrotate, editors that save by replacing the original inode, services that truncate and recreate logs, and backup tools that expect to rename files. A program may write a temporary file and atomically rename it rather than append to the existing inode, so test the complete application workflow before deploying this flag. It reduces local rewriting; it does not provide a trusted remote audit trail.

Rank #4
Sale
YOTUO 500GB External Hard Drive, Portable Storage Expansion HDD, USB 3.0 & USB-C for PC, Mac, Desktop, Laptop, Smartphone, PS4, Xbox One, Xbox 360, Office & Game Black
  • 【Versatile Storage Expansion – For Gaming, Work & Everyday Use】 Running out of space on your PS5 or Xbox Series X/S? This external hard drive lets you store and play PS4 / Xbox One games directly, instantly freeing up your console’s internal storage for next‑gen titles. At the same time, it handles work file backups, media libraries, and cross‑device data transfers with ease. One drive, all your needs. *(Note: PS5 / Xbox Series X|S games cannot be run or stored directly from the external hard drive. However, by offloading your PS4 / Xbox One games, you can free up valuable space for newer titles.)*
  • 【Patented Silicone Sleeve – Data Protection You Can Count On】 Worried about drops? We’ve got you covered. The patented built‑in silicone sleeve acts like a shock‑absorbing armor, cushioning your drive against bumps and falls. Whether it’s important work documents, precious family photos, or hard‑earned game saves, your data deserves this level of protection.
  • 【Plug & Play, Compatible with Computers & Consoles】 No complicated setup—just plug in and go. Works seamlessly with Windows, Mac, and Linux computers, as well as PS4, PS5, Xbox One, and Xbox Series X/S. Process files at the office, back up data at home, or enjoy gaming in your downtime—one drive handles all your devices, simply and hassle‑free.
  • 【USB 3.0 Ultra‑Fast Transfer – No More Waiting】 Tired of watching progress bars crawl? With USB 3.0 speeds up to 5Gbps, large files transfer in seconds. Whether you’re moving work documents, transferring hundreds of gigs of games, or backing up a year’s worth of photos, you get more done in less time.
  • 【Sleek, Lightweight, and Ready to Go】 Weighing just 0.16 kg—lighter than a can of soda—this compact drive features a stylish mirror‑and‑frosted finish. Toss it in your bag and go, whether you’re heading to the office, visiting a friend for a gaming session, or giving a presentation on the road.

Apply attributes to directories

Set a flag on the directory itself

sudo chattr +i config-directory
lsattr -d config-directory

An immutable directory blocks normal changes to its entries and metadata, including creation, deletion, and renaming within that directory. Setting +i on the directory does not automatically set i on every child file.

An append-only directory has filesystem-dependent semantics. It generally restricts removal and renaming while permitting certain additions; it does not make every child file append-only. Verify behavior on the target filesystem rather than assuming that all descendants inherit +a.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Apply recursively

find directory/ -print
find directory/ -type f -exec lsattr {} +
sudo chattr -R +i directory/
sudo chattr -R -i directory/

-R affects the entire tree. Avoid broad recursive operations on /, /etc, /usr, /var, home directories, mounted backups, or application data unless you have a tested recovery plan. A recursive undo does not restore each file’s previous mixed attribute state; it merely removes the named flag everywhere.

Best Value
Sale
WD 2TB Elements Portable External Hard Drive for Windows, USB 3.2 Gen 1/USB 3.0 for PC & Mac, Plug and Play Ready - WDBU6Y0020BBK-WESN
  • High capacity in a small enclosure – The small, lightweight design offers up to 6TB* capacity, making WD Elements portable hard drives the ideal companion for consumers on the go.
  • Plug-and-play expandability
  • Vast capacities up to 6TB[1] to store your photos, videos, music, important documents and more
  • SuperSpeed USB 3.2 Gen 1 (5Gbps)
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Important flags at a glance

Flag Meaning Typical use Limitation
i Immutable Block ordinary changes to a file or directory Setting or clearing requires appropriate privilege, commonly CAP_LINUX_IMMUTABLE
a Append-only Restrict logs or audit files to appends Applications must append; rotation and atomic replacement can fail
A No atime updates Reduce metadata writes Mount options and filesystem behavior also control atime
c Compress Filesystem compression where implemented Not broadly supported; notably relevant on supported Btrfs configurations
C No copy-on-write Disable CoW for selected files Btrfs generally requires an empty file when setting or clearing it
d No dump Exclude from the traditional dump utility Modern backup programs may ignore it
D Synchronous directory updates Make directory changes synchronous Can reduce performance
S Synchronous file updates Write file updates synchronously Can reduce performance
j Data journaling Per-file data journaling where supported Depends on filesystem and mount mode
e Extent format Diagnostic display Normally not manually changed

Current manuals also list specialized or historical flags such as F, m, P, s, t, T, u, and x. Letters such as E, I, N, and V may be read-only information in lsattr. Availability and meaning vary; use the local manual and filesystem documentation.

Troubleshoot failures safely

“Operation not permitted”

  1. Inspect existing flags: lsattr -d path.
  2. Check the mount: findmnt -T path -o TARGET,FSTYPE,OPTIONS.
  3. Confirm you are using sufficient privilege.
  4. Check whether the filesystem is read-only or lacks the requested operation.
  5. On Btrfs, check flag ordering and empty-file restrictions.

Only clear a flag that is actually present:

sudo chattr -i path
sudo chattr -a path

Do not respond by running sudo chattr -R -i /; that can create a larger and less understood change.

“Inappropriate ioctl for device”

This usually means the underlying filesystem or filesystem layer does not implement the inode-flag operation. Identify it with findmnt -T; installing another package will not add support to an incompatible mount.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Btrfs constraints

Btrfs supports a subset of chattr flags. Its Ubuntu Btrfs documentation states that C has empty-file restrictions, c and C cannot be combined, and m and c cannot be combined. Btrfs also has a separate xflags interface; that is not the same mechanism as setting ordinary extended attributes.

Choose the right protection

  • Use chmod or ACLs when the requirement is user- or group-specific read/write access. ACLs express per-user policy; chattr is a coarse inode-level restriction.
  • Use encryption such as LUKS or application-level encryption when confidentiality is the goal. chattr leaves contents readable.
  • Use backups and snapshots for recovery. The d flag only concerns the traditional dump utility, not every modern backup product.
  • Use a read-only mount when an entire filesystem or mount view should be protected, rather than selected paths.
  • Use centralized or remote logging when audit integrity matters. Append-only mode alone cannot protect against a privileged administrator who can clear the flag or replace the storage.

Safe end-to-end demonstration

mkdir -p ~/chattr-demo
cd ~/chattr-demo
printf 'original textn' > demo.txt
lsattr demo.txt
sudo chattr +i demo.txt
lsattr demo.txt
sudo chattr -i demo.txt
printf 'now editable againn' >> demo.txt
sudo chattr +a demo.txt
echo 'append works' >> demo.txt
sudo chattr -a demo.txt
rm demo.txt

This sequence uses a home-directory test file and includes the corresponding unlock commands, so it does not leave a system configuration or log permanently locked.

Quick Recap

SaleBestseller No. 1
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$129.99
Bestseller No. 2
Seagate Portable 5TB External Hard Drive HDD – USB 3.0 for PC, Mac, PS4, & Xbox - 1-Year Rescue Service (STGX5000400), Black
Seagate Portable 5TB External Hard Drive HDD – USB 3.0 for PC, Mac, PS4, & Xbox - 1-Year Rescue Service (STGX5000400), Black
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$180.19
Bestseller No. 3
Seagate Portable 1TB External Hard Drive HDD – USB 3.0 for PC, Mac, PlayStation, & Xbox, 1-Year Rescue Service (STGX1000400) , Black
Seagate Portable 1TB External Hard Drive HDD – USB 3.0 for PC, Mac, PlayStation, & Xbox, 1-Year Rescue Service (STGX1000400) , Black
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$119.80
SaleBestseller No. 5

Quick command reference

lsattr file
sudo chattr +i file
sudo chattr -i file
sudo chattr +a file
sudo chattr -a file
sudo chattr -R +i directory/
sudo chattr -R -i directory/

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.