The chattr command is used to change file properties. This directive changes the properties of files or directories stored on the ext2 file system
Command syntax
> chattr [-rv][-v< version number >][+/-/=< properties >][File or directory...]Copy the code
Command options
- -r Indicates that all files and subdirectories in a specified directory are processed at the same time.
- -v< version number > Sets the version of a file or directory.
- -v Displays the command execution process.
- +< properties > Enables the property of a file or directory.
- -< properties > Disables the property of a file or directory.
- =< property > Specifies the property of a file or directory.
attribute
- A: Make files or directories for additional use only;
- B: do not update the last access time of a file or directory;
- C: Compress files or directories and save them.
- D: Exclude files or directories from dumping operation;
- I: Do not arbitrarily change files or directories;
- S: confidential deletion of files or directories;
- S: Update files or directories immediately.
- U: Prevent accidental deletion.
Use the chattr command to prevent a critical file from being modified:
> chattr +i /etc/my.cnf
Copy the code
Viewing File Properties
> lsattr /etc/my.cnf
----i-------- /etc/my.cnf
Copy the code
Use chattr to apply restrictions to all files in a directory
> chattr -R +i ./rumenz
Copy the code
You can only add data to a file, but cannot delete it. This applies to all log files
> chattr +a /var/log/a.log
Copy the code
Original link :rumenz.com/rumenbiji/l… Wechat official account: entry station