Easy Tutorial
❮ Linux Tutorial Linux Comm Ulimit ❯

Linux lsattr Command

Linux Command Manual

The Linux lsattr command is used to display file attributes.

To change the attributes of a file or directory with chattr, you can use the lsattr command to query its attributes.

Syntax

lsattr [-adlRvV][file or directory...]

Parameters:

Examples

  1. Use the chattr command to prevent a critical file in the system from being modified:
    # chattr +i /etc/resolv.conf
    

Then, commands like mv /etc/resolv.conf will result in "Operation not permitted".

When editing the file with vim, it will prompt "W10: Warning: Changing a readonly file". To modify this file, the i attribute must be removed:

chattr -i /etc/resolv.conf

Use the lsattr command to display the file attributes:

# lsattr /etc/resolv.conf

The output will be:

----i-------- /etc/resolv.conf
  1. Allow a file to only have data appended to it but not deleted, suitable for various log files:
    # chattr +a /var/log/messages
    

Linux Command Manual

❮ Linux Tutorial Linux Comm Ulimit ❯