Detailed explanation of lsattr command and chattr command

grammar:

lsattr [-adlRvV][文件或目录...]

parameter:

-a  显示所有文件和目录,包括以"."为名称开头字符的额外内建,现行目录"."与上层目录".."。
-d  显示,目录名称,而非其内容。
-l  此参数目前没有任何作用。
-R  递归处理,将指定目录下的所有文件及子目录一并处理。
-v  显示文件或目录版本。
-V  显示版本信息。

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 the result is Operation not permitted.

When vim edits the file, it will prompt W10: Warning: Changing a readonly file error. To modify this file, remove the i attribute:

chattr -i /etc/resolv.conf

Use the lsattr command to display file attributes:

lsattr /etc/resolv.conf
输出结果为:

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

2. Let a file only add data to it, but not delete it, which is applicable to various log files:

chattr +a /var/log/messages

Guess you like

Origin blog.csdn.net/m0_46829545/article/details/131049709