linux 中文件的隐藏属性

发布时间 2023-12-31 00:18:00作者: 小鲨鱼2018

 

001、设置文件不能被修改,同时也不能删除给文件: 

chattr +i file

a、修改

[root@pc1 test]# ls
a.txt
[root@pc1 test]# lsattr a.txt      ## 查看隐藏属性无
---------------- a.txt
[root@pc1 test]# chattr +i a.txt   ## 增加隐藏属性,文件不能被修改
[root@pc1 test]# lsattr a.txt      ## 查看多出了i, 表示无法修改
----i----------- a.txt
[root@pc1 test]# echo "xxx" >> a.txt   ## 尝试修改,失败
-bash: a.txt: Permission denied

 

b、删除

[root@pc1 test]# ls
a.txt
[root@pc1 test]# lsattr a.txt
----i----------- a.txt
[root@pc1 test]# rm a.txt            ## 即便是root用户也没法删除该文件
rm: cannot remove ‘a.txt’: Operation not permitted
[root@pc1 test]# chattr -i a.txt     ## 去除i的权限
[root@pc1 test]# lsattr a.txt
---------------- a.txt
[root@pc1 test]# rm a.txt

 

 

002、