Windowsでいうショートカットのような役割を持っているのがシンボリックリンクだ。
例えば,とても深い階層にあるディレクトリにアクセスする機会が多い場合には,次のように設定しておけば,キー入力を減らすことができる。
$ ln -s /www/bsd/home/user/ ./bsd |
上記は,/www/bsd/home/user/ディレクトリを,/bsdとして関連付ける設定だ。
$ cd /www/bsd/home/user/ |
通常であれば,上記のように入力しなければならないものが,「cd bsd」と入力するだけで済んでしまう。また,ユーザーによる設定以外にも,このシンボリックリンクはシステム上でも多用されている。
例えば,ランレベル別のサービス起動設定には,Linuxの場合次のようなディレクトリ構造でシンボリックリンクされている。
/etc/rc.d/内には,次のようなディレクトリが含まれているが,サービスを起動するプログラムの実体は,init.d/の中にある。
$ ls -l total 56 drwxr-xr-x 2 root root 4096 Aug 9 19:12 init.d -rwxr-xr-x 1 root root 2881 Sep 21 1999 rc -rwxr-xr-x 1 root root 1049 Aug 8 19:42 rc.local -rwxr-xr-x 1 root root 12864 Oct 12 1999 rc.sysinit drwxr-xr-x 2 root root 4096 Jul 10 17:28 rc0.d drwxr-xr-x 2 root root 4096 Jul 10 17:28 rc1.d drwxr-xr-x 2 root root 4096 Jul 10 17:28 rc2.d drwxr-xr-x 2 root root 4096 Jul 10 17:28 rc3.d drwxr-xr-x 2 root root 4096 Jul 10 17:28 rc4.d drwxr-xr-x 2 root root 4096 Jul 10 17:28 rc5.d drwxr-xr-x 2 root root 4096 Jul 10 17:28 rc6.d |
例えば,ランレベル3の時に実行されるサービスはrc3.d/の中にあり,init.d/内のプログラムへシンボリックリンクされている。
これにより,ランレベル別の個々のディレクトリ内には,起動させたいサービスだけをini.d/へシンボリックリンクしておけばよいのだ。
$ ls -l total 160 -rw-r--r-- 1 root root 1742 Aug 9 19:03 1 -rwxr-xr-x 1 root root 1231 Sep 21 1999 apmd -rwxr-xr-x 1 root root 827 Sep 10 1999 arpwatch -rwxr-xr-x 1 root root 1871 Feb 19 2000 atalk.init -rwxr-xr-x 1 root root 989 Aug 17 1999 atd -rwxr--r-- 1 root root 1024 Oct 22 1999 canna -rwxr-xr-x 1 root root 1031 Sep 11 1999 crond -rwxr-xr-x 1 root root 7386 Sep 21 1999 functions -rwxr-xr-x 1 root root 1261 Sep 24 1999 gpm -rwxr-xr-x 1 root root 3164 Oct 5 1999 halt -rwxr-xr-x 1 root root 865 Dec 18 1999 httpd 〜以下略〜 |
シンボリックリンクされている状態は,「ls -l」などと指定してみると把握できる。
以下は,rc3.d/ディレクトリ下の状態だ。すべてシンボリックリンクであり,実体はinit.d/にあることが分かる。
$ ls -l total 0 lrwxrwxrwx 1 root root 15 Feb 1 2000 K10pulse -> ../init.d/pulse lrwxrwxrwx 1 root root 13 Feb 1 2000 K10xfs -> ../init.d/xfs lrwxrwxrwx 1 root root 13 Feb 1 2000 K20nfs -> ../init.d/nfs lrwxrwxrwx 1 root root 16 Feb 1 2000 K20rstatd -> ../init.d/rstatd lrwxrwxrwx 1 root root 17 Feb 1 2000 K20rusersd -> ../init.d/rusersd lrwxrwxrwx 1 root root 15 Feb 1 2000 K20rwhod -> ../init.d/rwhod lrwxrwxrwx 1 root root 18 Feb 1 2000 K30sendmail -> ../init.d/sendmail 〜以下略〜(※折り返し整形をしています) |
Copyright © ITmedia, Inc. All Rights Reserved.