一.chattr命令格式
格式
chattr [+-=][選項] 檔案或目錄名
操作
+: 增加權限
-: 洗掉權限
=: 等于某權限
選項
i:
如果對檔案設定i屬性,那么不允許對檔案進行洗掉/改名,也不能添加和修改資料;(相當于鎖死檔案,什么操作都不允許進行,對root用戶也生效)
如果對目錄設定i屬性,那么只能修改目錄下檔案的資料,但不允許建立和洗掉檔案.
a:
如果對檔案設定a屬性,那么只能在檔案中增加資料,但是不能洗掉也不能修改資料;(相當于鎖死檔案中現有的資料,只能添加新的資料[不能使用vi或vim,只能使用>>],其他的操作都不允許進行,對root生效)
如果對目錄設定a屬性,那么只允許在目錄中建立和修改檔案,但是不允許洗掉.
實體
## 檔案添加i屬性
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# touch test
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# echo 111 >> test
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# cat test
111
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# chattr +i test
# i代表i屬性,e代表檔案是在ext檔案系統下建立的
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# lsattr -a test
----i--------e-- test
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# echo 222 >> test
-bash: test: Permission denied
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# rm -rf test
rm: cannot remove ‘test’: Operation not permitted
## 檔案夾添加i屬性
# 創建檔案夾test
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# mkdir test
# 在test檔案夾下新建檔案aaa
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# touch test/aaa
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# ls test
aaa
# 給檔案夾test添加i屬性
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# chattr +i test
# test檔案夾有i屬性,aaa沒有i屬性
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# lsattr -a test
----------I--e-- test/..
----i--------e-- test/.
-------------e-- test/aaa
# 檔案aaa可以編輯
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# echo 111 >> aaa
# 在test檔案夾下不可以新建檔案
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# touch test/abc
touch: cannot touch ‘test/abc’: Permission denied
# 在洗掉test檔案夾下的aaa沒有權限
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# rm -rf test/aaa
rm: cannot remove ‘test/aaa’: Permission denied
## 檔案添加a屬性
二.查看檔案系統屬性
格式
lsattr 選項 檔案名
選項
-a: 顯示所有檔案和目錄
-d: 若目標是目錄,僅列出目錄本身的屬性,而不是子檔案
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/137080.html
標籤:Linux
下一篇:linux下su與sudo
