文件属性的添加与查看
语法 添加 chattr +i 文件路径 ----+i是不允许对文件有任何的修改(包括root用户也不可以),可以查看.
chattr +a 文件路径 ------不允许覆盖此文件的内容,只能追加,,root不可以删除和移动此文件.
.
查看文件的属性 lsattr 文件路径
[root@ggbond opt]# chattr +a file2
[root@ggbond opt]# lsattr file2
-----a---------- file2
[root@ggbond opt]# echo '我是'>> file2
[root@ggbond opt]# cat file2
我是
[root@ggbond opt]# echo '云计算' >> file2
[root@ggbond opt]# cat file2
我是
云计算
[root@ggbond opt]# echo '运维' > file2 ----不可以覆盖
-bash: file2: 不允许的操作
[root@ggbond opt]# rm -rf file2 ----root也不可以删除
rm: 无法删除"file2": 不允许的操作
[root@ggbond opt]# mv file2 /home
mv: 无法将"file2" 移动至"/home/file2": 不允许的操作 -----root也不可以移动
[root@ggbond opt]# chattr +i file1
[root@ggbond opt]# lsattr file1
----i----------- file1
[root@ggbond opt]# rm -rf file1 ----root也不可以删除
rm: 无法删除"file1": 不允许的操作
[root@ggbond opt]# mv file1 /home ----root也不可以移动
mv: 无法将"file1" 移动至"/home/file1": 不允许的操作
取消权限
语法: chattr -i 文件路径
chattr -a 文件路径
[root@ggbond opt]# lsattr file1
----i----------- file1
[root@ggbond opt]# lsattr file2
-----a---------- file2
[root@ggbond opt]# chattr -i file1 -----减去即可
[root@ggbond opt]# chattr -a file2
[root@ggbond opt]# lsattr file1
---------------- file1
[root@ggbond opt]# lsattr file2
---------------- file2