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

 

相关文章

Centos系统之Shell编程基础知识
从Export理解Shell环境和变量生存期
linux shell数组变量、类型及规则
Centos编程Shell基本工作原理方案
Centos操作系统编程之Shell 问答录
rsync-linux备份脚本