linux 中文件的隐藏属性

 

001、设置文件不能被修改,同时也不能删除给文件: 

chattr +i file

a、修改

复制代码
[root@pc1 test]# ls
a.txt
[root@pc1 test]# lsattr a.txt      ## 查看隐藏属性无
---------------- a.txt
[root@pc1 test]# chattr +i a.txt   ## 增加隐藏属性,文件不能被修改
[root@pc1 test]# lsattr a.txt      ## 查看多出了i, 表示无法修改
----i----------- a.txt
[root@pc1 test]# echo "xxx" >> a.txt   ## 尝试修改,失败
-bash: a.txt: Permission denied
复制代码

 

b、删除

复制代码
[root@pc1 test]# ls
a.txt
[root@pc1 test]# lsattr a.txt
----i----------- a.txt
[root@pc1 test]# rm a.txt            ## 即便是root用户也没法删除该文件
rm: cannot remove ‘a.txt’: Operation not permitted
[root@pc1 test]# chattr -i a.txt     ## 去除i的权限
[root@pc1 test]# lsattr a.txt
---------------- a.txt
[root@pc1 test]# rm a.txt
复制代码

 

 

002、设置仅允许追加, 不能覆盖和删除

复制代码
[root@pc1 test]# ls
a.txt
[root@pc1 test]# cat a.txt                ## 测试文件
1
2
3
[root@pc1 test]# chattr +a a.txt          ## 设置隐藏权限a,仅允许追加
[root@pc1 test]# lsattr a.txt
-----a---------- a.txt
[root@pc1 test]# echo "hello world" > a.txt     ## 无法清空
-bash: a.txt: Operation not permitted
[root@pc1 test]# echo "hello world" >> a.txt   ## 可以追加
[root@pc1 test]# cat a.txt
1
2
3
hello world
[root@pc1 test]# rm a.txt                       ## 无法删除
rm: cannot remove ‘a.txt’: Operation not permitted
复制代码

 

posted @   小鲨鱼2018  阅读(208)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2022-12-31 linux 中wget命令的几个常用选项
2022-12-31 从NCBI中下载SRA数据
2022-12-31 linux 中对带有空格、括号的文件进行重命名
2022-12-31 linux 中删除文件名中的括号
2022-12-31 linux 中删除文件名中的空格
2022-12-31 linux中统计文本中每一行中空格的总数目
2022-12-31 linux 中实现文件名的补齐
点击右上角即可分享
微信分享提示