linux中防止文件被意外删除
1、测试文件
root@PC1:/home/test3# ls root@PC1:/home/test3# touch a.txt b.txt ## 测试文件 root@PC1:/home/test3# ls a.txt b.txt root@PC1:/home/test3# lsattr a.txt b.txt ## 查看属性,是一致的 --------------e----- a.txt --------------e----- b.txt root@PC1:/home/test3# ls a.txt b.txt root@PC1:/home/test3# chattr +i a.txt ## 对a.txt增加权限 root@PC1:/home/test3# lsattr a.txt b.txt ## 查看属性 ----i---------e----- a.txt --------------e----- b.txt root@PC1:/home/test3# rm a.txt ## 已经无法删除a.txt rm: cannot remove 'a.txt': Operation not permitted root@PC1:/home/test3# rm b.txt ## 删除b.txt root@PC1:/home/test3# lsattr a.txt ----i---------e----- a.txt root@PC1:/home/test3# chattr -i a.txt ## 清除i的权限 root@PC1:/home/test3# lsattr a.txt --------------e----- a.txt root@PC1:/home/test3# rm a.txt ## 可以删除a.txt