chmod 更改權限
rwx數字分别表示 4 2 1,則rwx=7 r-x=5 r--=4 等等
1、檢視檔案或目錄詳細資訊
[root@wy ~]# ls -l
總用量 48
-rw-r--r-- 1 root root 0 9月 21 03:06 1.txt
-rw-------. 1 root root 1460 9月 9 02:39 anaconda-ks.cfg
-rw-r--r--. 1 root root 29745 9月 9 02:39 install.log
-rw-r--r--. 1 root root 6995 9月 9 02:37 install.log.syslog
2、修改 1.txt 的權限
[root@wy ~]# chmod 744 1.txt
-rwxr--r-- 1 root root 0 9月 21 03:06 1.txt
3、還可以這樣修改
[root@wy ~]# chmod u-x 1.txt
[root@wy ~]# ls -l 1.txt
-rw-r--r-- 1 root root 0 9月 21 2016 1.txt
[root@wy ~]# chmod u+x,g+w,o-r 1.txt
-rwxrw---- 1 root root 0 9月 21 2016 1.txt
4、用 a 來代表所有(ugo)
[root@wy ~]# chmod a+r 1.txt
-rwxrw-r-- 1 root root 0 9月 21 2016 1.txt
5、繼承權限(也就是一個目錄下的子目錄繼承父目錄的權限)
[root@wy ~]# ls -l 111
總用量 4
drwxr-xr-x 2 root root 4096 9月 20 19:55 222
-rw-r--r-- 1 root root 0 9月 20 19:54 22.txt
[root@wy ~]# chmod -R 700 111
drwx------ 2 root root 4096 9月 20 19:55 222
-rwx------ 1 root root 0 9月 20 19:54 22.txt
6、檢視目前使用者的 umask值
[root@wy ~]# umask
0022
它的作用是用來規定我們預設的目錄和檔案的權限
7、檢視目錄與檔案的預設權限
[root@wy ~]# mkdir 123
[root@wy ~]# ls -ld 123
drwxr-xr-x 2 root root 4096 9月 20 20:10 123 #目錄預設是755
[root@wy ~]# touch 123.txt
[root@wy ~]# ls -l 123.txt
-rw-r--r-- 1 root root 0 9月 20 20:10 123.txt #檔案預設是644
預設權限是通過umask來規定的,來推演出來的
linux下所有的目錄的權限必須要有 x 權限,為什麼要有 x 權限呢,可以這樣了解,目錄呢它是一個特殊的檔案,那這個檔案是可以存放東西的,作為一個目錄的話,我們應該能夠讓人去進入到這個目錄下去,進去然後再去更改或者建立或者删除等等這樣的操作,前提是我們必須要進入,可想而知,進入一個檔案,這是不是一個動作,一種行為,這種行為呢,讓它能夠讓我們去執行來行,它必須可執行,我們才能做這個動作,是以目錄必須要有 x 權限,不然,我們不可以進去。而文檔就沒有必要有執行權限了。是以這時,我們就有了一個推論的過程,umask是0022,通常情況下,隻用後三位022,即--- -w- -w- ,是以目錄的推演過程是:(rwx rwx rwx)-(--- -w- -w-)=rwx r-x r-x=755;同理檔案(沒必要有執行權限)的推演過程:(rw- rw- rw-)-(--- -w- -w-)=rw- r-- r--=644
8、改變umask值
[root@wy ~]# umask 0011
0011
随之預設的目錄和檔案的權限也會改變
[root@wy ~]# mkdir 1111
[root@wy ~]# ls -ld 1111
drwxrw-rw- 2 root root 4096 9月 20 20:29 1111
[root@wy ~]# touch 1111.txt
[root@wy ~]# ls -l 1111.txt
-rw-rw-rw- 1 root root 0 9月 20 20:29 1111.txt