chattr

Used to change file attributes

Supplementary instructions

chattr command is used to change file attributes. This command can change the attributes of files or directories stored on the ext2 file system. These attributes have the following 8 modes:

grammar

chattr(options)

Options

a: Let the file or directory be used only for additional purposes;
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: No files or directories may be changed arbitrarily;
s: delete files or directories with confidentiality;
S: Update files or directories immediately;
u: Prevent accidental deletion.
-R: Recursive processing, processing all files and subdirectories in the command directory together;
-v<version number>: set the file or directory version;
-V: Display the instruction execution process;
+<Attribute>: Turn on the attribute of the file or directory;
-<Attribute>: Turn off the attribute of the file or directory;
=<Attribute>: Specify the attribute of the file or directory.

Example

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

chattr +i /etc/fstab

Then try rm, mv, rename and other commands to operate on the file, and you will get the result of Operation not permitted.

Let a file only have content appended to it and cannot be deleted. Some log files are suitable for this operation:

chattr +a /data1/user_act.log