Linux File Attributes: Find and Remove Immutable Flags

Quick Linux Tip #86:

Question: Some files won't delete due to attributes. How do I find Linux file attributes?

Try: sudo lsattr -R /var/log 2>/dev/null | grep -E '^-*[aiu]' | head -10

Info: Linux file attributes control how files can be modified or deleted. The i attribute makes a file immutable, a enables append-only access, and u enables undeletable status. lsattr lists these attributes while chattr modifies them.

Examples:

  • $ sudo chattr +i /etc/resolv.conf  # Prevent DNS config modification
  • $ sudo chattr -i /etc/resolv.conf  # Remove immutable flag to allow edits
  • $ sudo chattr +a /var/log/audit.log  # Enforce append-only mode for audit logs

Note: Immutable files cannot be modified or deleted even by the root superuser without removing the i flag via chattr -i first. Check Linux file attributes before troubleshooting files that appear impossible to modify or delete.

Follow @LinuxTeck for more #LinuxTips




LinuxTeck.com
linuxteck:~$ sudo lsattr -R /var/log 2>/dev/null | grep -E '^-*[aiu]' | head -10
----i-----------e------- /var/log/system.log.protected
-----a----------e------- /var/log/audit.log
-----u----------e------- /var/log/recoverable.log

linuxteck:~$ sudo chattr -i /var/log/system.log.protected

linuxteck:~$ lsattr /var/log/system.log.protected
----------------e------- /var/log/system.log.protected

linuxteck:~$ sudo rm /var/log/system.log.protected
linuxteck:~$

PREVIOUS ARTICLE Quick Linux Tip #85: Count Error Occurrences in Linux Logs with Watch NEXT ARTICLE Quick Linux Tip #87: Linux Swap Usage: Find Processes Using the Most Swap
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.