You can use chattr to modify the attributes of a file or directory and run the lsattr command to query its attributes.
Syntax
Lsattr [-adlRvV] [file or directory...]
Parameters:
- -A displays all files and directories, including the additional built-in characters starting with ".", the current directory "." and the upper Directory "..".
- -D display, directory name, rather than its content.
- -L this parameter does not work currently.
- -R recursive processing: All files and subdirectories in the specified directory are processed together.
- -V: displays the file or directory version.
- -V displays the version information.
Instance
1. Use the chattr command to prevent the modification of a key file in the system:
# Chattr + I/etc/resolv. conf
Then run mv/etc/resolv. conf and other commands to operate on the file. Operation not permitted is obtained.
When editing the file, vim prompts the 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 the file attributes:
# Lsattr/etc/resolv. conf
Output result:
---- I --------/etc/resolv. conf
2. Allow a file to only append data to it, but not delete it. It is applicable to various log files:
# Chattr + a/var/log/messages