Linux文件的特殊属性chattr工具

简介:

        linux系统下有许多文件权限设定的命令,本文主要介绍chattr工具给文件加隐藏属性,可以增加重要文件的安全性。

一、给文件加a属性,增加该属性后,该文件只能追加内容而不能覆盖删除,lsattr查看chattr权限

1.添加a属性

[root@www ~]# lsattr 1.txt    
-------------e- 1.txt

[root@www ~]# chattr +a 1.txt   
[root@www ~]# lsattr 1.txt 
-----a-------e- 1.txt

[root@www ~]# echo 111112222244444 > 1.txt       //无法覆盖
-bash: 1.txt: Operation not permitted
[root@www ~]# echo 111112222244444 >> 1.txt    //追加内容
[root@www ~]# cat 1.txt 
111112222244444
[root@www ~]# rm -r 1.txt 
rm: remove regular file `1.txt'? y
rm: cannot remove `1.txt': Operation not permitted   //无法删除

2、去除a属性

[root@www ~]# chattr -a 1.txt 

[root@www ~]# echo 55555 > 1.txt     //覆盖内容
[root@www ~]# cat 1.txt 
55555


二、给文件加i属性,增加该属性后,该文件无法修改、删除

1、添加i属性

[root@www ~]# chattr +i 2.txt 
[root@www ~]# echo 1111 > 2.txt 
-bash: 2.txt: Permission denied
[root@www ~]# echo 1111 >> 2.txt 
-bash: 2.txt: Permission denied
[root@www ~]# rm -rf 2.txt 
rm: cannot remove `2.txt': Operation not permitted

2、去除i属性

[root@www ~]# chattr -i 2.txt
[root@www ~]# echo 2222 > 2.txt
[root@www ~]# cat 2.txt
2222


三、查看目录及其下所有文件的chattr属性,加-R选项

[root@www ~]# lsattr -R 222
-------------e- 222/222
222/222:
-------------e- 222/222/111
222/222/111:
-------------e- 222/222/111/123.txt
-------------e- 222/123.txt
-------------e- 222/install.log


[root@www ~]# chattr +i 222/222/111/123.txt

[root@www ~]# rm -rf 222
rm: cannot remove `222/222/111/123.txt': Operation not permitted

[root@www ~]# lsattr -R 222
-------------e- 222/222
222/222:
-------------e- 222/222/111
222/222/111:
----i--------e- 222/222/111/123.txt
-------------e- 222/123.txt
-------------e- 222/install.log


四、给目录增加chattr权限,加-d选项

[root@www ~]# lsattr -d 222
-------------e- 222
[root@www ~]# chattr +a 444
[root@www ~]# lsattr -d 444
-----a-------e- 444

本文转自 HMLinux 51CTO博客,原文链接:http://blog.51cto.com/7424593/1719932



相关文章
|
16天前
|
监控 Unix Linux
Linux操作系统调优相关工具(四)查看Network运行状态 和系统整体运行状态
Linux操作系统调优相关工具(四)查看Network运行状态 和系统整体运行状态
30 0
|
23天前
|
存储 前端开发 Linux
Linux系统之部署ToDoList任务管理工具
【4月更文挑战第1天】Linux系统之部署ToDoList任务管理工具
63 1
|
22天前
|
人工智能 安全 Linux
【Linux】Linux之间如何互传文件(详细讲解)
【Linux】Linux之间如何互传文件(详细讲解)
|
16天前
|
Linux
Linux操作系统调优相关工具(三)查看IO运行状态相关工具 查看哪个磁盘或分区最繁忙?
Linux操作系统调优相关工具(三)查看IO运行状态相关工具 查看哪个磁盘或分区最繁忙?
21 0
|
1天前
|
JSON Unix Linux
Linux系统之jq工具的基本使用
Linux系统之jq工具的基本使用
10 1
|
1天前
|
监控 安全 Linux
Linux系统之安装ServerBee服务器监控工具
【4月更文挑战第22天】Linux系统之安装ServerBee服务器监控工具
39 2
|
2天前
|
编解码 Linux 数据安全/隐私保护
linux工具之curl与wget高级使用
linux工具之curl与wget高级使用
|
2天前
|
固态存储 Ubuntu Linux
Linux(29) 多线程快速解压缩|删除|监视大型文件
Linux(29) 多线程快速解压缩|删除|监视大型文件
11 1
|
2天前
|
Ubuntu Linux 数据安全/隐私保护
Linux(24) 如何在Ubuntu中操作rootfs.img文件
Linux(24) 如何在Ubuntu中操作rootfs.img文件
3 0
|
7天前
|
安全 Linux 开发工具
Linux中可引起文件时间戳改变的相关命令
【4月更文挑战第12天】Linux中可引起文件时间戳改变的相关命令
16 0