用户身份与文件权限---文件的隐藏属性
Linux系统中的文件除了具备一般权限和特殊权限外,还有一种隐藏权限,即被隐藏起来的权限,默认情况下不能直接被用户发觉
1,chattr 命令
chattr 命令用于设置文件的隐藏权限,格式为 chattr [参数] 文件。
注意:
- 在命令后追加
+参数,把某个隐藏功能加到文件上 - 在命令后追加
-参数,把某个隐藏功能移除文件
chattr 命令中用于隐藏权限的参数及其作用
-
i:无法对文件进行修改;若对目录设置了该参数,则仅能修改其中的子文件内容而不能新建或删除文件 -
a:仅容许补充(追加)内容,无法覆盖/删除内容(Append Only) -
S:文件内容在变更后立即同步到硬盘(sync) -
s:彻底从硬盘中删除,不可恢复(用0填充原文件所在硬盘区域) -
A:不再修改这个文件或目录的最后访问时间 -
b:不再修改文件或目录的存取时间 -
D:检查压缩文件中的错误 -
d:使用dump命令备份时忽略本文件/目录 -
c:默认将文件或目录压缩 -
u:当删除该文件后依然保留其在硬盘中的数据,方便日后恢复 -
t:让文件系统支持尾部合并(tail-merging) -
x:可以直接访问压缩文件中的内容
示例:为文件增加隐藏权限a
[root@study doc]# echo "for test" > testfile
[root@study doc]# rm testfile
rm: remove regular file ‘testfile’? y
[root@study doc]# echo "for test" > testfile
[root@study doc]# chattr +a testfile
[root@study doc]# rm testfile
rm: remove regular file ‘testfile’? y
rm: cannot remove ‘testfile’: Operation not permitted
2,lsattr 命令
lsattr 命令用于显示文件的隐藏权限,格式为 lsattr [参数] 文件
示例:查看文件隐藏权限,删除隐藏权限
[root@study doc]# lsattr testfile
-----a-------e-- testfile
[root@study doc]# chattr -a testfile
[root@study doc]# lsattr testfile
-------------e-- testfile
[root@study doc]# rm testfile
rm: remove regular file ‘testfile’? y






网友评论