r/LinuxTeck • • 2d ago

Quick Linux Tip #126 - Linux Immutable File Attribute: Fix Files That Won't Delete

Post image

Question: Even root can't delete a file. What's wrong?

Try:`sudo lsattr /tmp/stuck.lock`

Info: 'i' attributes block all modifications even for root; remove them using chattr -i.

Examples:

$ `sudo chattr +i /etc/resolv.conf` # Protect configuration files from accidental modification

$ `sudo lsattr -R /etc | grep -E '^-*[ai]'` # Recursively find all immutable or append-only files

$ `sudo chattr -R -i /directory` # Remove immutable attributes recursively across a directory

Note: Malicious actors often apply the immutable (`+i`) attribute to lock down backdoors. Always check file attributes with `lsattr` if deletion fails unexpectedly. This feature is supported natively on ext2/3/4 filesystems.

Want to master Linux one command at a time?

Follow r/LinuxTeck - 1 practical Linux tip every day. For more #LinuxTips click here https://www.linuxteck.com/linux-tips/

10 Upvotes

0 comments sorted by