Linux平臺對連結檔案屬組、許可權的修改細節

liuhaimiao發表於2014-12-03

    在Linux平臺修改屬組的命令是chown,修改許可權的命令是chmod,這大家都知道,但在昨天的工作中才發現對連結檔案的修改與普通檔案
確是如此的不同,特地記錄下來:

1.建立連結檔案。

在root使用者的$HOME目錄下建立test目錄,並在該目錄下建立了a普通檔案和連結到a的b連結檔案。
[root@rhel1 ~]# mkdir test
[root@rhel1 ~]# cd test
[root@rhel1 test]# ls
[root@rhel1 test]# touch a
[root@rhel1 test]# ls
a
[root@rhel1 test]# ln -s a b
[root@rhel1 test]# ls -ald *
-rw-r--r-- 1 root root 0 May 31 14:10 a
lrwxrwxrwx 1 root root 1 May 31 14:10 b -> a

2.修改連結檔案的屬組。

[root@rhel1 test]# chown oracle:oinstall b
[root@rhel1 test]# ls -ald *
-rw-r--r-- 1 oracle oinstall 0 May 31 14:10 a
lrwxrwxrwx 1 root   root     1 May 31 14:10 b -> a

    沒有-R的chown命令實際修改的是連結檔案連結的普通檔案屬組。

[root@rhel1 test]# chown -R oracle:oinstall b
[root@rhel1 test]# ls -ald *
-rw-r--r-- 1 oracle oinstall 0 May 31 14:10 a
lrwxrwxrwx 1 oracle oinstall 1 May 31 14:10 b -> a
[root@rhel1 test]# chown -R root:root b
[root@rhel1 test]# ls -ald *
-rw-r--r-- 1 oracle oinstall 0 May 31 14:10 a
lrwxrwxrwx 1 root   root     1 May 31 14:10 b -> a

   加上-R的chown命令修改了連結檔案的屬組,但這不會修改連結檔案連結的普通檔案的屬組。

[root@rhel1 test]# cd ..
[root@rhel1 ~]# ls -ald test
drwxr-xr-x 2 root root 4096 May 31 14:10 test
[root@rhel1 ~]# chown -R grid:oinstall test
[root@rhel1 ~]# ls -al test
total 12
drwxr-xr-x  2 grid oinstall 4096 May 31 14:10 .
drwxr-x--- 11 root root     4096 May 31 14:09 ..
-rw-r--r--  1 grid oinstall    0 May 31 14:10 a
lrwxrwxrwx  1 grid oinstall    1 May 31 14:10 b -> a
[root@rhel1 ~]# ls -ald test
drwxr-xr-x 2 grid oinstall 4096 May 31 14:10 test

   對上層目錄執行加上-R的chown命令,這會修改目錄、目錄下的連結檔案,以及連結檔案連結的普通檔案的屬組,通常這才是我們想要的效果。

3.修改連結檔案的許可權。

[root@rhel1 ~]# cd test
[root@rhel1 test]# ll
total 0
-rw-r--r-- 1 grid oinstall 0 May 31 14:10 a
lrwxrwxrwx 1 grid oinstall 1 May 31 14:10 b -> a
[root@rhel1 test]# chmod 775 b
[root@rhel1 test]# ll
total 0
-rwxrwxr-x 1 grid oinstall 0 May 31 14:10 a
lrwxrwxrwx 1 grid oinstall 1 May 31 14:10 b -> a

   不加-R的chmod和chown命令的效果相同,修改的是連結檔案連結的普通檔案的許可權。

[root@rhel1 test]# chmod -R 660 b
[root@rhel1 test]# ll
total 0
-rw-rw---- 1 grid oinstall 0 May 31 14:10 a
lrwxrwxrwx 1 grid oinstall 1 May 31 14:10 b -> a

    加上-R的chmod也無法修改連結檔案的許可權。

[root@rhel1 test]# cd ..
[root@rhel1 ~]# chmod -R 600 test
[root@rhel1 ~]# ls -ald test
drw------- 2 grid oinstall 4096 May 31 14:10 test
[root@rhel1 ~]# ls -al test
total 12
drw-------  2 grid oinstall 4096 May 31 14:10 .
drwxr-x--- 11 root root     4096 May 31 14:09 ..
-rw-------  1 grid oinstall    0 May 31 14:10 a
lrwxrwxrwx  1 grid oinstall    1 May 31 14:10 b -> a

    對上層目錄執行-R的chmod命令可以修改目錄的許可權,目錄下連結檔案連結的普通檔案的許可權,但依然無法修改連結檔案的許可權。
   由此可以得出結論,連結檔案預設是777的許可權,且無法修改。

--end--

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/223653/viewspace-1354740/,如需轉載,請註明出處,否則將追究法律責任。

相關文章