【Linux】一步一步学Linux——chattr命令(115)
生活随笔
收集整理的這篇文章主要介紹了
【Linux】一步一步学Linux——chattr命令(115)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
00. 目錄
文章目錄
- 00. 目錄
- 01. 命令概述
- 02. 命令格式
- 03. 常用選項
- 04. 參考示例
- 05. 總結
- 06. 附錄
01. 命令概述
chattr命令用來改變文件屬性。這項指令可改變存放在ext2文件系統上的文件或目錄屬性,這些屬性共有以下幾種模式:
| i | 無法對文件進行修改;若對目錄設置了該參數,則僅能修改其中的子文件內容而不能新建或刪除文件 |
| a | 僅允許補充(追加)內容,無法覆蓋/刪除內容(Append Only) |
| S | 文件內容在變更后立即同步到硬盤(sync) |
| s | 徹底從硬盤中刪除,不可恢復(用0填充原文件所在硬盤區域) |
| A | 不再修改這個文件或目錄的最后訪問時間(atime) |
| b | 不再修改文件或目錄的存取時間 |
| D | 檢查壓縮文件中的錯誤 |
| d | 使用dump命令備份時忽略本文件/目錄 |
| c | 默認將文件或目錄進行壓縮 |
| u | 當刪除該文件后依然保留其在硬盤中的數據,方便日后恢復 |
| t | 讓文件系統支持尾部合并(tail-merging) |
| x | 可以直接訪問壓縮文件中的內容 |
如果想要把某個隱藏功能添加到文件上,則需要在命令后面追加“+參數”,如果想要把某個隱藏功能移出文件,則需要追加“-參數”。
02. 命令格式
用法:chattr [參數] 文件03. 常用選項
-R:遞歸處理,將指令目錄下的所有文件及子目錄一并處理; -v<版本編號>:設置文件或目錄版本; -V:顯示指令執行過程; +<屬性>:開啟文件或目錄的該項屬性; -<屬性>:關閉文件或目錄的該項屬性; =<屬性>:指定文件或目錄的該項屬性。04. 參考示例
4.1 設置無法對文件進行修改
[root@itcast test]# chattr +i file [root@itcast test]# echo "神馬程序員" >> file -bash: file: 權限不夠 [root@itcast test]#4.2 撤銷i屬性
[root@itcast test]# chattr +i file [root@itcast test]# echo "C++" >> file -bash: file: 權限不夠 [root@itcast test]# chattr -i file [root@itcast test]# echo "C++" >> file [root@itcast test]#4.3 允許補充(追加)內容,無法覆蓋/刪除內容
[root@itcast test]# chattr +a file [root@itcast test]# rm -f file rm: 無法刪除"file": 不允許的操作 [root@itcast test]# echo "hello itcast" >> file [root@itcast test]# cat file hello itcast [root@itcast test]#4.4 撤銷a屬性
[root@itcast test]# chattr -a file [root@itcast test]# echo > file [root@itcast test]#4.5 顯示指令執行過程
[root@itcast test]# chattr -V +i file chattr 1.42.9 (28-Dec-2013) file的標志被設為 ----i----------- [root@itcast test]#4.6 設置文件或目錄版本
[root@itcast test]# chattr -v 1 -V -i file chattr 1.42.9 (28-Dec-2013) file的標志被設為 ---------------- Version of file set as 1 chattr: 對設備不適當的 ioctl 操作 while setting version on file [root@itcast test]#4.7 刪除a屬性,增加c屬性
[root@itcast test]# chattr -V -v 2 -a +c file chattr 1.42.9 (28-Dec-2013) file的標志被設為 --------c------- chattr: 不支持的操作 while setting flags on file [root@itcast test]#05. 總結
06. 附錄
參考:【Linux】一步一步學Linux系列教程匯總
總結
以上是生活随笔為你收集整理的【Linux】一步一步学Linux——chattr命令(115)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Linux】一步一步学Linux——L
- 下一篇: 【Linux】一步一步学Linux——l