系統管理
1752380 會員
6185 線上
108788 解決方案
發表新文章

為什麼/sbin/lv* inode 都是一樣的

 
watermelonyu
教授

為什麼/sbin/lv* inode 都是一樣的

這些檔案都是hard link嗎,他是怎樣做到的

怎樣做才可以使用一個inode,卻可以執行不同指令

# ls -ali lv*

1508 -r-sr-xr-x 31 root sys 835584 Oct 26 2003 lvchange

1508 -r-sr-xr-x 31 root sys 835584 Oct 26 2003 lvcreate

1508 -r-sr-xr-x 31 root sys 835584 Oct 26 2003 lvdisplay

1508 -r-sr-xr-x 31 root sys 835584 Oct 26 2003 lvextend

1508 -r-sr-xr-x 31 root sys 835584 Oct 26 2003 lvlnboot

4則回覆 4
watermelonyu
教授

為什麼/sbin/lv* inode 都是一樣的

Hi :



That is a programming skill by checking

program name (arg0) to do the different

things. Such as the following script

$ cat a.sh

#!/usr/bin/sh

my_name=`basename $0`

case "$my_name" in

a.sh) echo I am run as a.sh, do the things as a.sh;;

b.sh) echo I am run as b.sh, do the things as b.sh;;

c.sh) echo I am run as c.sh, do the things as c.sh;;

*) echo What ? My name is $my_name ;;

esac



$ ln a.sh b.sh

$ ln a.sh c.sh

$ ls -ali

total 18

46166 drwxr-xr-x 2 ldw rco 96 Sep 7 10:50 .

43241 drwxr-xr-x 66 ldw rco 6144 Sep 7 10:45 ..

44325 -rwxr-xr-x 3 ldw rco 282 Sep 7 10:52 a.sh

44325 -rwxr-xr-x 3 ldw rco 282 Sep 7 10:52 b.sh

44325 -rwxr-xr-x 3 ldw rco 282 Sep 7 10:52 c.sh



Run it as :

$ ./a.sh

I am run as a.sh, do the things as a.sh

$ ./b.sh

I am run as b.sh, do the things as b.sh

$ ./c.sh

I am run as c.sh, do the things as c.sh

watermelonyu
教授

為什麼/sbin/lv* inode 都是一樣的

在 /sbin 底下的 ls -ali sw*, 也是很多都是同樣的 inode, 看完 Yoda 的解釋, 想必這些相同 inode 的指令,一定都是功能很相近, 所以利用一支程式撰寫而成, 再利用 Yoda 的方法, 來區分不同的 file name.
watermelonyu
教授

為什麼/sbin/lv* inode 都是一樣的

 
watermelonyu
教授

為什麼/sbin/lv* inode 都是一樣的