Linux Immutable File Attribute: Fix Files That Won't Delete

Quick Linux Tip #126:

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.




LinuxTeck.com
linuxteck:~$ sudo lsattr /tmp/stuck.lock
----i--------e------- /tmp/stuck.lock

linuxteck:~$ sudo rm /tmp/stuck.lock
rm: cannot remove '/tmp/stuck.lock': Operation not permitted

linuxteck:~$ sudo chattr -i /tmp/stuck.lock

linuxteck:~$ sudo lsattr /tmp/stuck.lock
-------------e------- /tmp/stuck.lock

linuxteck:~$ sudo rm /tmp/stuck.lock
linuxteck:~$

PREVIOUS ARTICLE Quick Linux Tip #125: Bash Startup Time: Find and Fix Slow Linux Shell Startup NEXT ARTICLE Quick Linux Tip #127: Linux Process Stack Trace: Find Where a Hung Process Is Stuck
About John Britto

John Britto Founder & Chief-Editor @LinuxTeck. A Computer Geek and Linux Intellectual having more than 20+ years of experience in Linux and Open Source technologies.

View all posts by John Britto →

Leave a Reply

Your email address will not be published.