English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Linux lsattr command

Linux Command大全

The Linux lsattr command is used to display file attributes.

Use chattr to change the attributes of files or directories, and use lsattr to query their attributes.

Syntax

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

Parameters:

  • -a Display all files and directories, including the built-in ones with names starting with ".", the current directory "." and the parent directory "..".
  • -d Display directory name, not its content.
  • -l This parameter currently has no effect.
  • -R Recursive processing, process all files and subdirectories under the specified directory at the same time.
  • -v Display file or directory version.
  • -V Display version information.

Online Examples

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

# chattr +i /etc/resolv.conf

Then use mv /etc/Operations such as resolv.conf on this file result in Operation not permitted.

When editing the file with vim, it will prompt W10: Warning: Changing a readonly file error. To modify this file, you need to remove the i attribute:

chattr -i /etc/resolv.conf

Use the lsattr command to display file attributes:

# lsattr /etc/resolv.conf

Output result is:

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

2Set a file to only append data and not delete, suitable for various log files:

# chattr +a /var/log/messages

Linux Command大全