在linux下面遇到这样的一个报错:
root@instance-byqryya4:/home# rm -f 1.txt
rm: cannot remove '1.txt': Operation not permitted
可以通过 lsattr
命令,查看该文件是否被打了file flags
:
root@instance-byqryya4:/home# lsattr 1.txt
----i---------e--- 1.txt
如果文件上存在 i 标记,那肯定是删不掉的,同样这个文件也不能被编辑,即使你拥有root权限
首先我们要进入 root
模式,之后使用chattr
来去除这个标记:
root@instance-byqryya4:/home# chattr -i 1.txt
root@instance-byqryya4:/home# lsattr 1.txt
--------------e--- 1.txt
同理,给文件添加保护的方式,就是增加这个标记:
root@instance-byqryya4:/home# chattr +i 1.txt