1. 程式人生 > 實用技巧 >linux系統中chmod命令

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