[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