chattr – change file attributes on a Linux file system(在Linux文件系统上更改文件属性)
设置隐藏权限
[root@evan-01 ~]# ls -l
total 12
-rw-------. 1 root root 6398 Aug 8 16:10 anaconda-ks.cfg
-rw-------. 1 root root 1257 Aug 8 18:36 anaconda-ks.cfg.bak
drwxrwxr--. 2 root root 6 Aug 9 11:15 test
-rw-rw-r--. 1 root root 0 Aug 9 11:14 test.txt
[root@evan-01 ~]# chattr +i test.txt
[root@evan-01 ~]#
设置后我们去编辑这个文件
[root@evan-01 ~]# vi test.txt
按 i 切换到插入模式后,下面出现警告:W10: Warning: Changing a readonly file(W10:警告:更改只读文件)
随便写入一些内容,按esc键,输入:wq保存退出,提示:‘E45 readonly’ option is set (add ! to override),设置了readonly选项,添加!覆盖
写入不进去,按 esc 键,输入:q! ,强制退出。
[root@evan-01 ~]# cat test.txt
[root@evan-01 ~]#
然后查看下文件,发现什么都没写入进去
尝试追加内容进去看可以吗
[root@evan-01 ~]# echo "123456" >> test.txt
-bash: test.txt: Permission denied
[root@evan-01 ~]#
究竟他有着什么权限,还不能编辑呢,看下
[root@evan-01 ~]# ls -l test.txt
-rw-rw-r--. 1 root root 0 Aug 9 11:14 test.txt
[root@evan-01 ~]#
是可读写的,没毛病呀。这些都没问题,那一定是有隐藏权限的
lsattr 查看隐藏权限
[root@evan-01 ~]# lsattr test.txt
----i--