Click the blue text to follow us

1. Introduction
The chattr command is used to change the attributes of files or directories, which can control the behavior of files or directories and provide advanced file management features.
2. Syntax
Syntax: chattr [options] [+/-/=attributes] file or directory
Parameter Description:
|
Parameter |
Description |
|
-R |
Recursively process directories and their subdirectories |
|
-V |
Display detailed information |
|
-v |
Display version information |
|
+ |
Add attribute |
|
– |
Remove attribute |
|
= |
Set to specified attribute |
Common Attribute Permissions:
|
Parameter |
Description |
|
a |
Append only: The file can only have content added, not deleted or modified (requires root permissions) |
|
i |
Immutable: The file cannot be deleted, modified, renamed, or have hard links created (requires root permissions) |
|
A |
Do not update the last access time of the file (atime) |
|
c |
File is automatically compressed on disk (supported by some file systems) |
|
s |
Secure delete: When the file is deleted, its data will be zeroed out (irrecoverable) |
|
u |
After the file is deleted, its content can still be recovered (opposite of s ) |
|
d |
The file will be skipped during dump backups |
3. Practical Examples
1. Add immutable attribute to a file
[root@app01 abc]# chattr +i test.txt
[root@app01 abc]# lsattr test.txt
----i----------- test.txt
2. Set append-only permission for a file
[root@app01 abc]# chattr +a 111.txt
[root@app01 abc]# lsattr 111.txt
-----a---------- 111.txt
3. Remove immutable attribute from a file
[root@app01 abc]# chattr -i test.txt
[root@app01 abc]# lsattr test.txt
---------------- test.txt
4. Remove all attributes, keeping only the “a” attribute
[root@app01 abc]# chattr =a test.txt
[root@app01 abc]# lsattr test.txt
-----a---------- test.txt
Using the ls command will not show these hidden attributes; you can use the lsattr command to view them. For more details, refer to the Linux command guide – lsattr command.
Long press the QR code to follow us


CSDN BlogδΈ¨Countless Stars in the Sky
https://blog.csdn.net/myself88129