linux系統中chmod命令


1、linux系統中文件和目錄的權限

按照用戶可分為所有者、所屬組和其他人。

所有者用u代表(user)

所屬組用g代表(group)

其他人用o代表(other)

按照具體的權限可以分為可讀、可寫、可執行、無權限

可讀用r代表(read),用數字4表示

可寫用w代表(write),用數字2表示

可執行用x代表(execute?),用數字1表示

 

2、linux中使用ll -l 、ls -l 、ls  -ld等命令查看文件或目錄權限

例如:

[root@linuxprobe test]# ll total 0
-rw-r--r--. 1 root root 0 Oct 20 20:59 a.txt drwxr-xr-x. 2 root root 6 Oct 20 21:00 test01

 

 

3、linux系統中使用chmod命令修改文件和目錄的權限

用法chmod  [選項} 文件,示例:

[root@linuxprobe test]# ll total 0
-rw-r--r--. 1 root root 0 Oct 20 20:59 a.txt drwxr-xr-x. 2 root root 6 Oct 20 21:00 test01 [root@linuxprobe test]# chmod u+x a.txt ## 所有者增加執行權限 [root@linuxprobe test]# ll total 0
-rwxr--r--. 1 root root 0 Oct 20 20:59 a.txt drwxr-xr-x. 2 root root 6 Oct 20 21:00 test01 [root@linuxprobe test]# chmod u-x,g+w test01/  ## 所有者減去執行權限,同時所屬組增加寫得全選 [root@linuxprobe test]# ll total 0
-rwxr--r--. 1 root root 0 Oct 20 20:59 a.txt drw-rwxr-x. 2 root root 6 Oct 20 21:00 test01 [root@linuxprobe test]# chmod u=rw,g=r,o=x a.txt ## 直接按照所有者、所屬組、其他人賦予權限 [root@linuxprobe test]# ll total 0
-rw-r----x. 1 root root 0 Oct 20 20:59 a.txt drw-rwxr-x. 2 root root 6 Oct 20 21:00 test01 [root@linuxprobe test]# chmod 421 test01/   ## 直接使用數字賦予權限 4表示所有者有讀的權限,2表示所屬組有寫的權限,1代表其他人具有執行的權限 [root@linuxprobe test]# ll total 0
-rw-r----x. 1 root root 0 Oct 20 20:59 a.txt dr---w---x. 2 root root 6 Oct 20 21:00 test01 [root@linuxprobe test]# chmod 777 a.txt ## 所有者、所屬組、其他人都具有可讀、可寫、可執行的權限 [root@linuxprobe test]# ll total 0
-rwxrwxrwx. 1 root root 0 Oct 20 20:59 a.txt dr---w---x. 2 root root 6 Oct 20 21:00 test01

 

3、修改目錄權限時,加 -R參數表示遞歸

[root@linuxprobe test]# mkdir test01 test02 ## 測試目錄 [root@linuxprobe test]# touch test01/a.txt ##測試文件 [root@linuxprobe test]# touch test02/b.txt ##測試文件 [root@linuxprobe test]# ll total 0 drwxr-xr-x. 2 root root 18 Oct 20 21:15 test01 drwxr-xr-x. 2 root root 18 Oct 20 21:15 test02 [root@linuxprobe test]# ls -l test01/a.txt -rw-r--r--. 1 root root 0 Oct 20 21:15 test01/a.txt [root@linuxprobe test]# ls -l test02/b.txt -rw-r--r--. 1 root root 0 Oct 20 21:15 test02/b.txt [root@linuxprobe test]# chmod 777 test01/   [root@linuxprobe test]# chmod -R 777 test02/  ## 添加 -R參數 [root@linuxprobe test]# ll total 0 drwxrwxrwx. 2 root root 18 Oct 20 21:15 test01 drwxrwxrwx. 2 root root 18 Oct 20 21:15 test02 [root@linuxprobe test]# ls -l test01/a.txt -rw-r--r--. 1 root root 0 Oct 20 21:15 test01/a.txt [root@linuxprobe test]# ls -l test02/b.txt ## test02目錄下的b.txt也賦予了777的權限 -rwxrwxrwx. 1 root root 0 Oct 20 21:15 test02/b.txt

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM