chmod命令用來變動文件或目錄的權限。在UNIX系統家族裏,文件或目錄權限的控制分別以讀取、寫入、執行3種通常權限來區分,另有3種特殊權限可供運用。用戶可使用chmod指令去變動文件與目錄的權限,設置方式採用文字或數字代號皆可。符號鏈接的權限沒法變動,若是用戶對符號鏈接修改權限,其改變會做用在被鏈接的原始文件。linux
權限範圍的表示法以下:ui
chmod (選項) (參數)
-c或——changes:效果相似「-v」參數,但僅回報更改的部分; -f或--quiet或——silent:不顯示錯誤信息; -R或——recursive:遞歸處理,將指令目錄下的全部文件及子目錄一併處理; -v或——verbose:顯示指令執行過程; --reference=<參考文件或目錄>:把指定文件或目錄的所屬羣組所有設成和參考文件或目錄的所屬羣組相同; <權限範圍>+<權限設置>:開啓權限範圍的文件或目錄的該選項權限設置; <權限範圍>-<權限設置>:關閉權限範圍的文件或目錄的該選項權限設置; <權限範圍>=<權限設置>:指定權限範圍的文件或目錄的該選項權限設置;
權限模式:指定文件的權限模式;
文件:要改變權限的文件。spa
Linux用 戶分爲:擁有者、組羣(Group)、其餘(other),Linux系統中,預設的情況下,系統中全部的賬號與通常身份使用者,以及root的相關信 息, 都是記錄在/etc/passwd
文件中。每一個人的密碼則是記錄在/etc/shadow
文件下。 此外,全部的組羣名稱記錄在/etc/group
內!.net
linux文件的用戶權限的分析圖code
r=可讀 //值爲4blog
w=可寫 //值爲2遞歸
x=可執行 //值爲1文檔
-=無權限 值爲0get
[root@localhost ~]# touch test.txt [root@localhost ~]# ll total 4 -rw-------. 1 root root 1523 Apr 4 18:27 anaconda-ks.cfg -rw-r--r--. 1 root root 0 Jun 13 16:22 test.txt
咱們能夠看到新建的test.txt文檔具備的權限:rw-r--r--,對應的值爲644。it
[root@localhost ~]# chmod u=rwx,g=rw,o=r test.txt [root@localhost ~]# ll total 4 -rw-------. 1 root root 1523 Apr 4 18:27 anaconda-ks.cfg -rwxrw-r--. 1 root root 0 Jun 13 16:22 test.txt
如今的權限爲rwxrw-r--,權限值爲764.
[root@localhost ~]# chmod u-x,g+x-w,o+x test.txt [root@localhost ~]# ll total 4 -rw-------. 1 root root 1523 Apr 4 18:27 anaconda-ks.cfg -rw-r-xr-x. 1 root root 0 Jun 13 16:22 test.txt
如今的權限是rw-r-xr-x,權限值爲655.
[root@localhost ~]# chmod a=r test.txt [root@localhost ~]# ll test.txt -r--r--r--. 1 root root 0 Jun 13 16:22 test.txt
如今的權限是r--r--r--,權限值爲444.
[root@localhost ~]# chmod a+x test.txt [root@localhost ~]# ll test.txt -r-xr-xr-x. 1 root root 0 Jun 13 16:22 test.txt
如今的權限是r-xr-xr-x,權限值爲555.
[root@localhost ~]# chmod 440 test.txt [root@localhost ~]# ll test.txt -r--r-----. 1 root root 0 Jun 13 16:22 test.txt
經過值更改權限後,一樣根據值的換算獲得文件權限:r--r-----,值爲440
[root@localhost ~]# chmod 777 test.txt [root@localhost ~]# ll test.txt -rwxrwxrwx. 1 root root 0 Jun 13 16:22 test.txt
上面是777權限。rwxrwxrwx.
[root@localhost ~]# ls -l total 4 -rw-------. 1 root root 1523 Apr 4 18:27 anaconda-ks.cfg drwxr-xr-x. 2 root root 45 Jun 13 16:36 test [root@localhost ~]# ls -l test total 0 -r--r--r--. 1 root root 0 Jun 13 16:36 test1 --w--w--w-. 1 root root 0 Jun 13 16:36 test2 ---x--x--x. 1 root root 0 Jun 13 16:36 test3
當前test目錄爲731權限,test目錄下的test1爲444權限,test2爲222權限,test3爲111權限。如今進行遞歸權限管理:
[root@localhost ~]# chmod -R 777 test [root@localhost ~]# ls -l total 4 -rw-------. 1 root root 1523 Apr 4 18:27 anaconda-ks.cfg drwxrwxrwx. 2 root root 45 Jun 13 16:36 test -rwxrwxrwx. 1 root root 0 Jun 13 16:22 test.txt [root@localhost ~]# ls -l test total 0 -rwxrwxrwx. 1 root root 0 Jun 13 16:36 test1 -rwxrwxrwx. 1 root root 0 Jun 13 16:36 test2 -rwxrwxrwx. 1 root root 0 Jun 13 16:36 test3
經過執行chmod -R 777 test命令,test目錄的權限以及其下的全部文件所有遞歸調整權限爲777。