- Published on
chattr command-change file attributes
Jonas
2 min read
The chattr command can change the file attributes of the linux file system. The general format is: +-=[aAcCdDeijsStTu] "aAcCdDeijsStTu" represents the new attributes that can be given to the file. These attributes have the following modes.
- a: Let the file or directory be for additional purposes only
- A: When a file with "A" attribute is accessed, its a time record will not be modified
- c: Save the file or directory after compression
- d: Exclude files or directories from dumping operations
- i: Do not change files or directories arbitrarily
- j: If the file system is installed with the "data=order" or "data=writeback" option, the file with the "j" attribute will write all its data into the ext 3 log before writing to the file itself
- s: When deleting a file with "s" attribute set, its block will be zeroed and written back to disk
- S: When modifying a file with the "S" attribute set, the change will be written to the disk synchronously. This is equivalent to the "synchronous" mount option applied to a subset of files
- u: When deleting a file with the 'u' attribute set, its content will be saved.
chattr [parameter] [file]
Command parameters:
-R | Recursively process all files in the directory |
-v | Set file or directory version |
-V | Show instruction execution process |
+ | Open the attribute of the file or directory |
- | Turn off the attribute of the file or directory |
= | Specifies the attribute of the file or directory |
Example
Use the chattr command to prevent a key file in the system from being modified (locked):[root@linuxstar ~]# chattr +i /etc/resolv.confUnlock:
[root@linuxstar ~]# chattr -i /home/omd/h.txtLet a file only add data to it, but not delete it, applicable to various log files:
[root@linuxstar ~]# chattr +a /var/log/messages