查看文件權限
# ls -l
total 59056
-rw-r--r-- 1 root root 36 Jun 3 05:20 A.txt
-rw-r--r-- 1 root root 27 Jun 3 05:20 B.txt
-rw-r--r-- 1 root root 48 Jun 2 00:42 data.txt
-rw-r--r-- 1 root root 95 Jun 2 00:41 file1.txt
-rw-r--r-- 1 root root 40 Jun 1 18:27 file1.txt~
-rw-r--r-- 1 root root 141 Jun 1 19:01 file3.txt
-rw-r--r-- 1 root root 60174336 Jun 3 19:11 file.txt
-rw-r--r-- 1 root root 98 Jun 1 19:05 file.txt~
-rw-r--r-- 1 root root 0 Jun 1 20:00 File.txt
-rw-r--r-- 1 root root 3653 Jun 1 01:21 index.html
-rw-r--r-- 1 root root 128257 May 24 23:19 jusched_525.log
-rw-r--r-- 1 root root 116154 Jun 1 00:28 log.txt
drwxr-xr-x 3 root root 4096 Jun 3 19:06 newDir
-rw-r--r-- 1 root root 12 Jun 3 04:50 number.txt
-rw-r--r-- 1 root root 0 Jun 1 01:19 plain_text_page.txt
-rw-r--r-- 1 root root 6 Jun 3 06:30 test
輸出的第一列描述了文件的權限,以下是對應表:
| - | it is a regular file. |
| d | if it is a directory |
| c | for a character device |
| b | for a block device |
| l | if it is a symbolic link |
| s | for a socket |
| p | for a pipe |
對於 -rw-r--r-- 來說,第一個"-"代表 文件。 第一組rw- 對應用戶權限,第二組r--對應組權限,第三組r--對應其他用戶的權限, 這三組中-代表對應的權限沒有設置。
用戶權限:
rwx------ 第一個字符位置 代表用戶是否有文件的讀權限,如果設置了用戶的讀權限,r將出現在這個位置。
第二個字符位置 代表用戶是否有修改權限,如果允許用戶修改,w將出現在這個位置。
第三個字符位置 代表用戶是否有執行權限,如果允許用戶執行,x將出現在這個位置。如果文件是可執行文件,通常設置執行權限。
用戶有一個特殊的權限, setuid(S), 可以出現在第三個字符的位置。代表即使其他用戶執行這個文件,可以和文件的所有者擁有一樣的效果。
---rwx--- 組權限
------rwx 其他用戶權限
設置權限
chmod u=rwx,g=rw,o=r A.txt //設置用戶權限rwx,組權限rw,其他用戶權限r
chmod g+x A.txt //為組用戶增加執行權限
chmod u-x A.txt //為用戶移除執行權限
chmod a-x filename //為所有角色移除執行權限
讀,寫,執行權限可以使用數字來代替
r-- 4
-w- 2
--x 1
rw- 4+2= 6
r-x 4+1 =5
因此rwx rw- r-- 指764
chmod 764 A.txt
rwx 4+2+1=7
特殊的目錄權限
目錄有一個特殊權限 t/T,如果設置了這個權限,此目錄的文件只能被擁有此權限的用戶刪除,即使組和其他用戶寫目錄的寫權限,也不能刪除文件
------rwt , ------rwT
遞歸的為目錄設定權限
chmod 777 . –R
