昨日举荐:每天学一个 Linux 命令(23):file
命令简介
chattr 用来扭转文件(扩大)属性。通常咱们叫这个属性为非凡属性。
lsattr 查看文件扩大属性。
这种非凡属性有以下8种模式:
a #限定文件具备某种性能。这个对于日志文件十分有作用,比方,不容许删除,只容许向外面追加内容。 b #不更新或批改文件或目录的最初存储工夫 c #将文件或目录压缩后存储 d #将文件或目录排除在倾倒操作之外 i #锁定文件或目录,不被更改 s #机密删除文件或目录 S #动静实时更新文件或目录 u #避免文件或目录被意外删除
如果文件或目录被配置了上述8种之一的扩大属性,通过lsattr命令能够查看到:
[root@centos7 testdir]# lsattr ----i----------- ./dir #后果阐明这个目录被配置扩大属性 [root@centos7 testdir]# chattr -i dir [root@centos7 testdir]# lsattr ---------------- ./dir
语法格局
chattr [选项] mode file lsattr [选项] file
选项阐明
chattr选项阐明
-R #递归解决,将目录下的所有文件及子目录都加上此扩大属性 -v<版本编号> #设置文件或目录版本号 -V #显示指令执行过程; + <属性> #增加文件或目录的某个扩大属性 - <属性> #解除文件或目录的某个扩大属性 = <属性> #指定某个扩展性至指定的文件或目录
lsattr选项阐明
-E #显示属性的以后值 -D #显示扩大属性的名称 -R #递归 -V #显示版本信息 -a #列出目录下所有文件,包含暗藏文件 #留神-E -D -R三个选项是不能够一起应用的,它们是互相排挤的。
利用举例
#避免误删除的作用 [root@centos7 testdir]# chattr +a test2.txt [root@centos7 testdir]# lsattr test2.txt -----a---------- test2.txt #不容许间接替换,只容许追加内容 [root@centos7 testdir]# echo "12345">test2.txt -bash: test2.txt: Operation not permitted #查看文件或目录有没有扩大属性 [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
这两个命令在日常工作也会罕用到,锁定文件,或者当文件或零碎呈现故障时用于排查。
[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
比方上述情况,如果此文件是一个要实时存储数据的文件,被锁定了,那么就可能会引发利用运行故障,所以,这时就能够通过lsattr命令来查看与排查。
每天学一个 Linux 命令(22):pwd
每天学一个 Linux 命令(21):tree