天天看點

通過 chmod 助記文法來改變檔案或目錄的權限

chmod 的助記文法相對簡單,對檔案或目錄權限的改變時,是通過比較直覺的字元的形式來完成;在助記文法中,相關字母的定義;

使用者或使用者組定義:

u 代表屬主

g 代表屬組

o 代表其它使用者

a 代表屬主、屬組和其它使用者,也就是上面三個使用者(或組)的所有;

權限定義字母:

r 代表讀權限;

w 代表寫權限;

x 代表執行權限;

權限增減字元;

- 代表減去相關權限;

+ 代表增加相關權限;

示例一:

​[root@localhost ~]# ls -l linuxsir007.txt -rwxr-xr-x 1 root root 0 04-23 20:11 linuxsir007.txt [root@localhost ~]# chmod ugo-x linuxsir007.txt 注:把屬主、使用者組及其它使用者的執行權限都減掉; [root@localhost ~]# ls -l linuxsir007.txt -rw-r--r-- 1 root root 0 04-23 20:11 linuxsir007.txt​

示例二:

​[root@localhost ~]# ls -l linuxsir007.txt -rw-r--r-- 1 root root 0 04-23 20:11 linuxsir007.txt [root@localhost ~]# chmod u+x linuxsir007.txt 注:為檔案的屬主增加執行權限  [root@localhost ~]# ls -l linuxsir007.txt  -rwxr--r-- 1 root root 0 04-23 20:11 linuxsir007.txt​

示例三:

​[root@localhost ~]# ls -l linuxsir007.txt  -rwxr--r-- 1 root root 0 04-23 20:11 linuxsir007.txt [root@localhost ~]# chmod u-x,go+rw linuxsir007.txt 注:減去檔案屬主對檔案的執行權,增加屬組和其它使用者對檔案的可讀可寫權; [root@localhost ~]# ls -l linuxsir007.txt -rw-rw-rw- 1 root root 0 04-23 20:11 linuxsir007.txt​

用助記文法比較靈活,組合起來比較友善;比如;

u=r+x 為檔案屬主添加讀寫權限;

ug=rwx,o=r 為屬主和屬組添加讀、寫、執行權限,為其它使用者設定讀權限。

a+x 為檔案的屬主、屬組和其它使用者添加執行權限;

g=u 讓檔案的屬組和屬主和權限相同;

對于目錄權限的設定,要用到-R參數;

和八進制方法一樣,如果我們為一個目錄及其下的子目錄和檔案具有相同的屬性,就可以用-R參數;

​[root@localhost ~]# chmod -R a+rwx testdir/ [root@localhost ~]# ls -lr testdir/ 總計 4 -rwxrwxrwx 1 root root    0 04-24 11:01 sir01.txt drwxrwxrwx 2 root root 4096 04-24 11:01 linuxsir​

繼續閱讀