chattr Used to change files （ Expand ） attribute . Usually we call this property a special property .
lsattr View file extension properties .
This special property has the following 8 Patterns ：
a # The qualification file has some function . This is very useful for log files , such as , Deletion is not allowed , Only content can be added to it . b # Do not update or modify the last storage time of a file or directory c # Compress a file or directory and store it d # Exclude files or directories from the dump operation i # Lock file or directory , Not changed s # Secretly delete files or directories S # Dynamically update files or directories in real time u # Prevent files or directories from being accidentally deleted
If the file or directory is configured with the above 8 One of the extended properties , adopt lsattr The command can see ：
[root@centos7 testdir]# lsattr ----i----------- ./dir # The result shows that the directory is configured with extended properties [root@centos7 testdir]# chattr -i dir [root@centos7 testdir]# lsattr ---------------- ./dir
chattr [ Options ] mode file lsattr [ Options ] file
chattr Option description
-R # Recursive processing , Add this extended attribute to all files and subdirectories in the directory -v< Version number > # Set the file or directory version number -V # Display during execution of instructions ; + < attribute > # Add an extended property of a file or directory - < attribute > # Release an extended attribute of a file or directory = < attribute > # Specify an extensibility to a specified file or directory
lsattr Option description
-E # Displays the current value of the property -D # Displays the name of the extended property -R # recursive -V # Display version information -a # List all files in the directory , Including hidden files # Be careful -E -D -R The three options can't be used together , They are mutually exclusive .
# The function of preventing false deletion [root@centos7 testdir]# chattr +a test2.txt [root@centos7 testdir]# lsattr test2.txt -----a---------- test2.txt # Direct substitution is not allowed , Only additional content is allowed [root@centos7 testdir]# echo "12345">test2.txt -bash: test2.txt: Operation not permitted # See if the file or directory has extended properties [root@centos7 testdir]# echo "12345">>test2.txt [root@centos7 testdir]# lsattr ---------------- ./dir ---------------- ./test2.txt~ -----a---------- ./test2.txt lsattr: Operation not supported While reading flags on ./cp
These two commands are also commonly used in daily work , Lock file , Or when a file or system fails, it can be used for troubleshooting .
[root@centos7 testdir]# lsattr ---------------- ./dir ---------------- ./test2.txt~ ----i----------- ./test2.txt lsattr: Operation not supported While reading flags on ./cp [root@centos7 testdir]# echo "12345">>test2.txt -bash: test2.txt: Permission denied
For example, the above situation , If this file is a file to store data in real time , locked , Then it may cause application running failure , therefore , Now you can go through lsattr Command to view and check .
This article is from WeChat official account. - The road of technology for migrant workers （jishuroad）
The source and reprint of the original text are detailed in the text , If there is any infringement , Please contact the firstname.lastname@example.org Delete .
Original publication time ： 2021-01-21
Participation of this paper Tencent cloud media sharing plan , You are welcome to join us , share .