umask 查詢及設定預設權限。
chattr 改變檔案的隱藏屬性。
lsattr 顯示檔案的隱藏屬性。
(-rw-rw-rw-) – (-----w--w-) ==> -rw-r--r--
(drwxrwxrwx) – (-----w--w-) ==> drwxr-xr-x
[root@dywHome2 test]# umask [-S] [mode]
參數說明:
-S(Symbolic): 以符號類型顯示權限
#範例:
[root@dywHome2 test]# umask
0022
[root@dywHome2 test]# umask -S
u=rwx,g=rx,o=rx
[root@dywHome2 test]# touch foo1
[root@dywHome2 test]# mkdir test1
[root@dywHome2 test]# ll
total 1
-rw-r--r-- 1 root root 0 Sep 4 10:53 foo1
drwxr-xr-x 2 root root 1024 Sep 4 10:54 test1/
[root@dywHome2 test]# umask 002
[root@dywHome2 test]# umask u=rwx.g=rwx,o=rx
[root@dywHome2 test]# touch foo2
[root@dywHome2 test]# mkdir test2
[root@dywHome2 test]# ll
total 2
-rw-r--r-- 1 root root 0 Sep 4 10:53 foo1
-rw-rw-r-- 1 root root 0 Sep 4 10:54 foo2
drwxr-xr-x 2 root root 1024 Sep 4 10:54 test1/
drwxrwxr-x 2 root root 1024 Sep 4 10:54 test2/
[root@dywHome2 test]# chattr +-=[ASacDdIijsTtu] [檔案或目錄名稱]
參數說明:
+-= :分別為 [+ 增加] [- 減少] [= 設定] 屬性。
A :存取時間 atime (access) 不可被修改。(驗證未成功)
S :類似 sync 的功能,會將資料同步寫入磁碟中。
a :檔案只能增加資料,而不能刪除,只有 root 才能設定這個屬性。 ###
c :自動將檔案『壓縮』,讀取時會自動解壓縮。
d :當 dump (備份)程序被執行時,設定 d 屬性將可使該檔案(或目錄)具有 dump 功效。
i :檔案不能被刪除、改名、設定連結也無法寫入或新增資料。 ###
j :檔案在寫入時先記錄在 journal 中。
s :檔案會被完全的移除出硬碟空間。
u :與 s 相反,資料內容還存在磁碟中,可以 undeletion。
The letters 'acdijsuADST' select the new attributes for the files:
append only (a), compressed (c), no dump (d), immutable (i), data jour-
nalling (j), secure deletion (s), no tail-merging (t), undeletable (u),
no atime updates (A), synchronous directory updates (D), synchronous
updates (S), and top of directory hierarchy (T).
#範例:
[root@dywHome2 test]# chattr +a foo
[root@dywHome2 test]# echo append > foo
-bash: foo: Operation not permitted
[root@dywHome2 test]# echo append >> foo
[root@dywHome2 test]# cat foo
append
[root@dywHome2 test]# chattr +i foo
[root@dywHome2 test]# mv foo foo1
mv: cannot move `foo' to `foo1': Operation not permitted
[root@dywHome2 test]# chattr -i foo
[root@dywHome2 test]# mv foo foo1
[root@dywHome2 test]# lsattr [-adR]
參數說明:
-a :列出所有檔案,含隱藏檔;
-d :只列出目錄,而不列目錄內容;
-R :連同子目錄一併列出。
#範例:
[root@dywHome2 test]# lsattr
----ia------- ./foo
------------- ./test1
------------- ./foo2
------------- ./test2
練習題