Show file attributes

Linux lsattr command syntax

Function:The lsattr command is used to display file attributes. Use chattr to change the attributes of a file or directory, and execute the lsattr command to query its attributes.

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

Linux lsattr command example

1. Use the chattr command to prevent a key file in the system from being modified:

# chattr +i /etc/resolv.conf

Then use commands such as mv /etc/resolv.conf to operate on the file, and you will get the result of Operation not permitted.

When vim edits the file, it will prompt W10: Warning: Changing a readonly file error. If you want to modify this file, you must remove the i attribute:

chattr -i /etc/resolv.conf

Use the lsattr command to display the file attributes:

# lsattr /etc/resolv.conf

The output result is:

----i-------- /etc/resolv.conf

2. Let a certain The file can only append data to it, but cannot delete it. It is suitable for various log files:

# chattr +a /var/log/messages