[root@hf-01 ~]# chattr +i 33.txt 给33.txt(空文件)增长了隐藏属性 [root@hf-01 ~]# vi 33.txt 是没法进去编辑文件,增长内容的,强制保存都不能够,它会提示说只有可读权限 [root@hf-01 ~]# head -n2 /etc/passwd > 33.txt -bash: 33.txt: 权限不够 将文件写入到33.txt文件中,也会提示权限不够 [root@hf-01 ~]# ls -l 33.txt 但查看的时候会看到有可读可写的权限,这时就要想要它是否添加了隐藏属性 -rw-rw-r--. 1 root root 0 10月 26 08:56 33.txt [root@hf-01 ~]# lsattr 33.txt 可查看33.txt添加了i隐藏属性 ----i----------- 33.txt [root@hf-01 ~]# touch ha.txt [root@hf-01 ~]# lsattr ha.txt 查看ha.txt文件的隐藏属性 ---------------- ha.txt Try 'mv --help' for more information. [root@hf-01 ~]# mv 33.txt 56.txt 这时修改将文件更名,会发现没法实现 mv: 没法将"33.txt" 移动至"56.txt": 不容许的操做 [root@hf-01 ~]# rm 33.txt 也没法去删除该文件,就算加-f强制去删除,再去查看的时候,会看到文件依旧存在 rm:是否删除普通空文件 "33.txt"?y rm: 没法删除"33.txt": 不容许的操做 [root@localhost ~]# touch 1.txt 会发现也没法现更改 touch: 没法建立"1.txt": 权限不够
[root@localhost ~]# chattr -i 1.txt 删除隐藏属性 [root@localhost ~]# lsattr 1.txt 再来查看,会发现隐藏属性没了 ---------------- 1.txt [root@localhost ~]# mv 1.txt 3.txt 这时就能够更更名称了(编辑、删除均可以) [root@localhost ~]# touch 3.txt [root@localhost ~]# echo "gurui" > 3.txt [root@localhost ~]# chattr +a 3.txt 给文件增长a属性,会发现没法删除、编辑,添加内容,只能追加内容 [root@localhost ~]# rm 3.txt rm:是否删除普通空文件 "3.txt"?y rm: 没法删除"3.txt": 不容许的操做 [root@localhost ~]# vi 3.txt 没法编辑3.txt文件 [root@localhost ~]# echo "hanfeng shuaiguo" > 3.txt 没法添加内容进去 -bash: 3.txt: 不容许的操做 [root@localhost ~]# echo "hanfeng shuaiguo" >> 3.txt 只能追加内容进3.txt文件中 [root@localhost ~]# cat 3.txt gurui hanfeng shuaiguo [root@localhost ~]# echo "hanfeng shuaiguo" >> 3.txt 继续追加内容 [root@localhost ~]# cat 3.txt gurui hanfeng shuaiguo hanfeng shuaiguo [root@localhost ~]# touch 3.txt 能够更改时间信息 [root@localhost ~]# ls -l 3.txt -rw-r--r--. 1 root root 40 10月 26 15:41 3.txt
chattr +a 属性, 只能追加,能够touch更改时间信息,但不能删除,不能更更名字和内容bash
[root@localhost ~]# lsattr 3.txt -----a---------- 3.txt [root@localhost ~]# chattr -a 3.txt 会看到a属性去除了 [root@localhost ~]# lsattr 3.txt ---------------- 3.txt
+、-、=分别表示增长、删除、设定 给目录加特殊权限,目录下的文件的文件内容是能够更改的,这个权限只是做用于目录自己。ui
lsattr -d 查看目录的属性code
lsattr -R 会显示目录及子目录下的文件(一层或多层目录文件),如果不加-R,则仅仅显示一层目录文件orm
[root@localhost ~]# mkdir 111 [root@localhost ~]# lsattr 111 [root@localhost ~]# mkdir 111/222/ [root@localhost ~]# lsattr 111/ ---------------- 111/222 [root@localhost ~]# lsattr -d 111/ ---------------- 111/ [root@localhost ~]# chattr +i 111/ [root@localhost ~]# lsattr -d 111/ ----i----------- 111/ [root@localhost ~]# rm -r 111/ rm:是否进入目录"111/"? y rm:是否删除目录 "111/222"?y rm: 没法删除"111/222": 权限不够 [root@localhost ~]# mv 111 1212 mv: 没法将"111" 移动至"1212": 不容许的操做 [root@localhost ~]# touch 111/12.txt touch: 没法建立"111/12.txt": 权限不够 [root@localhost ~]# chattr -i 111/ 给目录去除-i属性 [root@localhost ~]# lsattr -d 111/ ---------------- 111/ [root@localhost ~]# chattr +a 111/ 给目录加上+a权限 [root@localhost ~]# touch 111/23.txt 只能追加一个文件(建立一个文件,也算是追加) [root@localhost ~]# head -n 2 /etc/passwd > 111/23.txt 给目录加了 [root@localhost ~]# cat 111/23.txt root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin [root@localhost ~]# chattr -a 111 [root@localhost ~]# chattr +i 111/ [root@localhost ~]# head -n 2 /etc/passwd > 111/23.txt [root@localhost ~]# [root@localhost ~]# lsattr -R 111/ 在加上-R会查看111/目录下的文件和111/子目录下的文件 ---------------- 111/222 111/222: ---------------- 111/23.txt ---------------- 111/12.txt [root@localhost ~]# lsattr 111/ 如果不加,就仅仅显示一层的目录文件 ---------------- 111/222 ---------------- 111/23.txt ---------------- 111/12.txt [root@localhost ~]# tree 111/ 111/ ├── 12.txt ├── 222 └── 23.txt 1 directory, 2 files
-a:相似于ls的-a选项,连同隐藏文件一同列出ci
-R:连通子目录子文件的数据一同列出同步
-d:查看目录自己的特殊权限io