Linux第二週學習筆記(11)

Linux第二週學習筆記(11)bash


2.17 隱藏權限lsattr_chattr
ide

chattr命令:是設置吟唱隱藏權限的命令,更改Linux文件系統上的文件屬性。學習

參數說明:spa

A:表示文件或目錄的atime將不可修改unix

s:會將數據同步寫入磁盤中同步

a:只能追加不能刪除,非root用戶不能設定該屬性it

c:自動解壓該文件,讀取時會自動解壓io

i:文件不能刪除、從命名、設定連接、寫入以及新增數據ast

lsattrlist attribute)命令:用於讀取文件或者目錄的特殊權限class

a:列出全部文件(包含隱藏文件)

R:連同子目錄一塊兒列出

d:只列出當前目錄

-----------------------------------------------------------------------------------------

chattr –i命令:文件不能刪除、從命名、設定連接、寫入以及新增數據

[root@daizhihong01 tmp]# ls -l

總用量 8

-rw-r--r--  1 root     root    0 2   1 22:09 123456.txt

-rw-r--r--  1 root     root    0 2   1 22:09 123.txt

-rw-r--r--  1 root     root    0 2   1 22:09 12.txt

-rw-r--r--  1 root     root    0 2   1 22:09 1.txt

 

1234567890qwweerrrii

~                                                                                                                                    ~                                                                                                                                    ~                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

E45: 'readonly' option is set (add ! to override) 不能編輯保存)

q!(強制退出)

[root@daizhihong01 tmp]# head -n2 /etc/passwd>1.txt

-bash: 1.txt: 權限不夠(不能寫入)

[root@daizhihong01 tmp]# ls -l 1.txt

-rw-r--r-- 1 root root 0 2   1 22:09 1.txt(從-rw-r--r—權限當中查看時能夠編輯的,可是不能編輯的話就要考慮是否設置了特殊的權限,這時咱們能夠使用lasttr命令查看這個文件的特殊權限)

[root@daizhihong01 tmp]# lsattr 1.txt

----i----------- 1.txt(加了特殊權限-i

[root@daizhihong01 tmp]# lsattr 12.txt

---------------- 12.txt(普通文件裏面是沒有-i特殊權限的)

不能覆蓋

[root@daizhihong01 tmp]# mv 1.txt 12.txt

mv:是否覆蓋"12.txt" y

mv: 沒法將"1.txt" 移動至"12.txt": 不容許的操做

不能刪除

[root@daizhihong01 tmp]# rm 1.txt

rm:是否刪除普通空文件 "1.txt"y

rm: 沒法刪除"1.txt": 不容許的操做

[root@daizhihong01 tmp]# rm -f 1.txt

rm: 沒法刪除"1.txt": 不容許的操做

能夠更改時間

[root@daizhihong01 tmp]# touch 1.txt

touch: 沒法建立"1.txt": 權限不夠

移除「i」權限

[root@daizhihong01 tmp]# chattr -i 1.txt

[root@daizhihong01 tmp]# lsattr 1.txt

---------------- 1.txt

減掉「i」參數之後就能夠編輯了

[root@daizhihong01 tmp]# vi 1.txt

[root@daizhihong01 tmp]# rm 1.txt

rm:是否刪除普通文件 "1.txt"y

-------------------------------------------------------------------------------------

chattr a命令:只能追加不能刪除,非root用戶不能設定該屬性

 [root@daizhihong01 tmp]# lsattr 12.txt

-----a---------- 12.txt

[root@daizhihong01 tmp]# chattr -a 12.txt

 [root@daizhihong01 tmp]# lsattr 12.txt

---------------- 12.txt

---------------------------------------------------------------------------------------

不能刪除

[root@daizhihong01 tmp]# rm 12.txt

rm:是否刪除普通空文件 "12.txt"y

rm: 沒法刪除"12.txt": 不容許的操做

[root@daizhihong01 tmp]# rm -f 12.txt

rm: 沒法刪除"12.txt": 不容許的操做

不能寫入

[root@daizhihong01 tmp]# vi 12.txt

 

qwjxjx

nxnxxxkx,

~                                                                                                                                    

~                                                                                                                                   

~                                                                                                                                    

~                                                                                                                                   

~                                                                                                                                    

                                                                                                                             

"12.txt"

"12.txt" E212: Can't open file for writing

Press ENTER or type command to continue

不能覆蓋:

[root@daizhihong01 tmp]# mv 12.txt 123.txt

mv:是否覆蓋"123.txt" y

mv: 沒法將"12.txt" 移動至"123.txt": 不容許的操做

能夠更改時間信息:

[root@daizhihong01 tmp]# touch 12.txt

[root@daizhihong01 tmp]# ls -l

總用量 8

-rw-r--r--  1 root     root    0 2   1 22:09 123456.txt

-rw-r--r--  1 root     root    0 2   1 22:09 123.txt

-rw-r--r--  1 root     root   65 2   1 23:03 12.txt

追加內容也不行:

[root@daizhihong01 tmp]# head -n2 /etc/passwd > 12.txt

-bash: 12.txt: 不容許的操做

從後面追加是能夠的:

[root@daizhihong01 tmp]# head -n2 /etc/passwd >> 12.txt

[root@daizhihong01 tmp]# cat 12.txt

root:x:0:0:root:/root:/bin/bash

bin:x:1:1:bin:/bin:/sbin/nologin

從後面追加的內容

a」權限能夠追加內容,能夠更改時間信息

-------------------------------------------------------------------------------------

[root@daizhihong01 tmp]# tree 001

001

└── 002

└── 003

[root@daizhihong01 tmp]# lsattr 001

---------------- 001/002

[root@daizhihong01 tmp]# lsattr -d 001(查看本目錄)

---------------- 001

目錄加上「i」權限:

[root@daizhihong01 tmp]# lsattr -d 001

----i----------- 001

不能刪除目錄:

[root@daizhihong01 tmp]# rm -r 001

rm:是否進入目錄"001"? y

rm:是否進入目錄"001/002"? y

rm:是否刪除目錄 "001/002/003"y

rm:是否刪除目錄 "001/002"y

rm: 沒法刪除"001/002": 權限不夠

不能覆蓋:

[root@daizhihong01 tmp]# mv 001 123456

mv: 沒法將"001" 移動至"123456": 不容許的操做

不能在目錄下建立文件:

[root@daizhihong01 tmp]# touch 001/123456.txt

touch: 沒法建立"001/123456.txt": 權限不夠

以上能夠看出給目錄加上「i」權限之後和文件加「i」權限之後是同樣的

去掉「i權限」:

[root@daizhihong01 tmp]# chattr -i 001

[root@daizhihong01 tmp]# lsattr  001

---------------- 001/002

目錄加上「a」權限:

[root@daizhihong01 tmp]# chattr +a 001

[root@daizhihong01 tmp]# touch 001/123456.txt

[root@daizhihong01 tmp]# tree 001

001

├── 002

└── 123456.txt

1 directory, 1 file

是可在目錄下追加文件的

編輯目錄下文件的內容:

[root@daizhihong01 tmp]# vi 123456.txt

 

123456wenjian

~                                                                                                                                   

~                                                                                                                                    

~                                                                                                                                   

~                                                                                                                                    

~                                                                                                                                   

~                                                                                                                                    

~                                                                                                                                    

~                                                         

:wq

[root@daizhihong01 tmp]# cat 123456.txt

123456wenjian

目錄加了「a」之後能更改目錄下文件的內容

目錄加「i」之後編輯目錄下的文件:

[root@daizhihong01 tmp]# chattr -a 001

[root@daizhihong01 tmp]# chattr +i 001

[root@daizhihong01 tmp]# head -n2 /etc/passwd > 001/123456.txt

 [root@daizhihong01 tmp]# cat 001/123456.txt

root:x:0:0:root:/root:/bin/bash

bin:x:1:1:bin:/bin:/sbin/nologin

只要是在目錄下存在的文件加「i」權限之後也是能夠編輯文件的

---------------------------------------------------------------------------------

lsattr –R命令:能夠查看主目錄下的子目錄及文件隱藏權限

[root@daizhihong01 tmp]# lsattr -R 001

---------------- 001/002

 

001/002:

 

---------------- 001/123456.txt

不加「R」的話僅僅只是查看一層的目錄

[root@daizhihong01 tmp]# lsattr 001

---------------- 001/002

---------------- 001/123456.txt

lsattr a命令:能夠查看主目錄下的子目錄及文件(包含隱藏文件)隱藏權限

[root@daizhihong01 tmp]# lsattr -a

---------------- ./.

---------------- ./..

---------------- ./yum.log

---------------- ./.font-unix

---------------- ./.ICE-unix

---------------- ./.Test-unix

---------------- ./.X11-unix

---------------- ./.XIM-unix

相關文章
相關標籤/搜索