chattr command
Command function: Change file properties.
Command syntax: chattr [parameter] [+/-/=< property;] [file or directory ...]
This directive alters the properties of files or directories stored on ext2, ext3, Ext4, XFS, Ubifs, ReiserFS, JFS file systems, which have the following 8 modes:
- A: Make the file or directory available for additional use only.
- B: Do not update the last access time of the file or directory.
- C: Compress the file or directory and store it.
- D: Exclude files or directories from dumping operations.
- I: Do not alter the file or directory arbitrarily.
- S: Privacy delete files or directories.
- S: Update files or directories instantly.
- U: Remove outside of prevention.
With the three operator +/-/=, you can add and delete attributes to a file or directory.
Command parameters:
- -R recursively handles all files and subdirectories under the specified directory.
- -v< version number > set file or directory version.
- -V Displays the instruction execution process.
- +< Properties > Open the Item property of the file or directory.
- -< Properties > Close the Item property of the file or directory.
- The =< property > Specifies the Item property of the file or directory.
This command can only be performed by Superuser root.
Example:
1. Limit a file to append only the contents of the file, not modify and delete the file (this scenario is suitable for the log file), and output the instruction execution process
If you modify this file now, an error will occur:
When modifying a file, an error occurred and the following command could be used to append the contents of the file:
By >> implementation of the file appended,> is to overwrite the contents of the file.
2. The settings file must not be arbitrarily changed by adding the attribute I
After adding the attribute I, and then adding content to the file, a permission error occurs, so that even the root user cannot modify the file.
lsattr command
Command function: Displays the file properties, after the chattr command is exhausted, you can use the lsattr command to view the file properties
Such as:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"Linux command-File management class" Chattr command and Lsattr command