3.文件治理

本章同步视频https://edu.51cto.com/sd/e4874


3.3.2 隐藏权限

1.查看隐藏权限

(1)隐藏权限的效果

[root@localhost tmp]# ll aaa

-rw-r--r--. 1 root root 6 Mar 13 21:33 aaa

[root@localhost tmp]# echo "bbbb">aaa

-bash: aaa: Operation not permitted

#注:文件的拥有者且为root,明显具有写权限,却不能向aaa中写入数据。

(2)查看隐藏权限

[root@localhost tmp]# lsattr aaa

-----a---------- aaa

2.设置隐藏权限

(1)设置a属性:不能写入,只能追加

[root@localhost tmp]# cat aaa

aaaa

[root@localhost tmp]# chattr +a aaa

[root@localhost tmp]# echo "bbbb">aaa   

-bash: aaa: Operation not permitted          #写入失败

[root@localhost tmp]# cat aaa

aaaa                                                           #aaa的内容未发生变化

[root@localhost tmp]# echo "bbbb">>aaa   #追加内容乐成

[root@localhost tmp]# cat aaa

aaaa

bbbb                                    #aaa的内容被追加了bbbb

(2)作废a属性

[root@localhost tmp]# chattr -a aaa

[root@localhost tmp]# cat aaa

aaaa

[root@localhost tmp]# echo "bbbb">aaa

[root@localhost tmp]# cat aaa

bbbb

(3)设定i属性,不能写入,不能追加,不能删除

[root@localhost tmp]# chattr =i aaa

[root@localhost tmp]# cat aaa

aaaa

bbbb

[root@localhost tmp]# echo "cccc">aaa

-bash: aaa: Permission denied

[root@localhost tmp]# echo "cccc">>aaa

-bash: aaa: Permission denied

[root@localhost tmp]# rm -f aaa

rm: cannot remove ‘aaa’: Operation not permitted