http://blog.chinaunix.net/uid-223060-id-2215406.html
2011-05-19
文件屬性和權限
[root@daf root]# ls -al
total 64
drwxr-x--- 4 root root 4096 Feb 14 22:02 .
drwxr-xr-x 23 root root 4096 Feb 16 13:35 ..
-rw-r--r-- 1 root root 1210 Feb 10 06:03 anaconda-ks.cfg
-rw------- 1 root root 12447 Feb 14 23:22 .bash_history
-rw-r--r-- 1 root root 24 Jun 11 2000 .bash_logout
-rw-r--r-- 1 root root 234 Jul 6 2001 .bash_profile
-rw-r--r-- 1 root root 217 Feb 9 22:06 .bashrc
-rw-r--r-- 1 root root 210 Jun 11 2000 .cshrc
drwx------ 2 root root 4096 Feb 14 21:54 .gnupg
-rw------- 1 root root 8 Feb 14 22:05 .mysql_history
drwx------ 2 root root 4096 Feb 10 00:44 .ssh
-rw-r--r-- 1 root root 196 Jul 11 2000 .tcshrc
-rw-r--r-- 1 root root 1126 Aug 24 1995 .Xresources
一 二 三 四 五 六 七
[文件屬性][節點(diǎn)數][作者][所屬群組] [大小][創(chuàng )建時(shí)間] [文件名]
*文件名中帶有[ . ]開(kāi)頭的代表隱藏文件。
文件類(lèi)型代碼:[ d ]--目錄、[ - ]--文件、[ l ]--鏈接、[ b ]--可儲存周邊設備、[ c ]--序列設備。
文件權限屬性:[ r ]--可讀、[ w ]--可寫(xiě)、[ x ]--可執行。
*對于目錄,必需具有執行權限才可進(jìn)入
*文件的執行屬性將決定文件是否可執行,而與文件擴展名無(wú)關(guān)
改變權限設置:
chgrp :改變所屬群組
*要改變的群組名必須在 /etc/group 中存在
語(yǔ)法:
chgrp 群組名 文件或目錄
如:
[root@test root]# chgrp users tmp
[root@test root]# ls –l
drwx------ 2 root root 4096 Oct 19 11:43 drakx/
drwx------ 2 root users 4096 Oct 19 21:24 tmp/
[root@test root]# chgrp testing tmp
chgrp: invalid group name `testing' <==出錯信息!
chown :改變作者
[ -R ] :同時(shí)對目錄下的所有子目錄或文件的作者進(jìn)行修改
*用戶(hù)名必須已存在系統中,也就是在 /etc/passwd 中存在的用戶(hù)名。
*chown 可直接修改所屬群組
語(yǔ)法:
chown [ -R ] 用戶(hù)名 文件或目錄
chown [ -R ] 用戶(hù)名:群組名 文件或目錄
如:
[root@test root]# chown test tmp
[root@test root]# ls -l
total 28
drwx------ 2 root root 4096 Oct 19 11:43 drakx/
drwx------ 2 test users 4096 Oct 19 21:24 tmp/
[root@test root]# chown –R root:root tmp
[root@test root]# ls –l
drwx------ 2 root root 4096 Oct 19 11:43 drakx/
drwx------ 2 root root 4096 Oct 19 21:24 tmp/
chmod :改變權限屬性
方式一 數字類(lèi)型改變
三個(gè)基本屬性:r、w、x的數字類(lèi)型代表:r:4、w:2 、x:1
語(yǔ)法:
chmod [-R] xyz 文件或目錄
xyz 為三組 rwx 屬性數值的相加
同一組的數字是相加!如屬性為 [ -rwxrwx--- ] ,則:
owner = rwx = 4+2+1 = 7
group = rwx = 4+2+1 = 7
others = --- = 0+0+0 = 0
[root@test root]# ls –al .bashrc
-rw-r--r-- 1 root root 226 Feb 16 2002 .bashrc
[root@test root]# chmod 777 .bashrc
[root@test root]# ls –al .bashrc
-rwxrwxrwx 1 root root 226 Feb 16 2002 .bashrc
方式二 符號類(lèi)型改變
九個(gè)屬性分別代表是(1)user (2)group (3)others 三個(gè)群組的權限,可以由 u, g, o 來(lái)代表三個(gè)群組!而 a 則代表 all 亦即全部。
chmodu
g
o
a+(加入)
-(除去)
=(設定)r
w
x文件或目錄
[root@test root]# chmod u=rwx,og=rx .bashrc
[root@test root]# ls –al .bashrc
-rwxr-xr-x 1 root root 226 Feb 16 2002 .bashrc
[root@test root]# ls –al .bashrc
-rwxr-xr-x 1 root root 226 Feb 16 2002 .bashrc
[root@test root]# chmod a+w .bashrc
[root@test root]# ls –al .bashrc
-rwxrwxrwx 1 root root 226 Feb 16 2002 .bashrc
[root@test root]# chmod a-x .bashrc
[root@test root]# ls –al .bashrc
-rw-rw-rw- 1 root root 226 Feb 16 2002 .bashrc