歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> 系統運維技巧(一)——chattr和lsattr命令

系統運維技巧(一)——chattr和lsattr命令

日期:2017/3/1 15:37:09   编辑:關於Linux
系統運維技巧(一)——chattr和lsattr命令 我們有這樣的需求:一個文件不允許別人修改、刪除或者只允許添加,我們就可以使用chattr命令。 [plain] [root@serv01 test]# cat note.txt 1.不許遲到 2.不許早退 3.不許抽煙 [root@serv01 test]# chattr +i note.txt #root用戶都不能編輯 [root@serv01 test]# vim note.txt [root@serv01 test]# cat note.txt 1.不許遲到 2.不許早退 3.不許抽煙 #root用戶不能刪除 修改 [root@serv01 test]# rm -f note.txt rm: cannot remove `note.txt': Operation not permitted [root@serv01 test]# echo "this is test" >> note.txt -bash: note.txt: Permission denied #ll查看文件屬性不能看到,需要使用lsattr查看 [root@serv01 test]# ll note.txt -rw-r--r--. 1 root root 45 Sep 21 17:46 note.txt [root@serv01 test]# lsattr note.txt ----i--------e- note.txt #root用戶不能修改只是個相對概念,root用戶可以修改文件的屬性,就可以修改了 [root@serv01 test]# chattr -i note.txt [root@serv01 test]# lsattr note.txt -------------e- note.txt [root@serv01 test]# vim note.txt [root@serv01 test]# cat note.txt 1.不許遲到 2.不許早退 3.不許抽煙 4.可以不來上班 #留言板:自己說的話不能刪除 [root@serv01 test]# vim note.txt [root@serv01 test]# cat note.txt 1.不許遲到 2.不許早退 3.不許抽煙 4.可以不來上班 hello [root@serv01 test]# chattr +a note.txt [root@serv01 test]# lsattr note.txt -----a-------e- note.txt [root@serv01 test]# vim note.txt [root@serv01 test]# ls note.txt note.txt~ note.txy~ note.txz~ #刪除,發現沒有權限 [root@serv01 test]# rm -rf * rm: remove regular file `note.txt'? y rm: cannot remove `note.txt': Operation not permitted [root@serv01 test]# ls note.txt upload [root@serv01 test]# echo "hello world" > note.txt -bash: note.txt: Operation not permitted #只能使用追加的方式添加內容 [root@serv01 test]# echo "hello world" >> note.txt [root@serv01 test]# cat note.txt 1.不許遲到 2.不許早退 3.不許抽煙 4.可以不來上班 hello hello world [root@serv01 test]# chattr -a note.txt [root@serv01 test]# lsattr note.txt -------------e- note.txt
Copyright © Linux教程網 All Rights Reserved