Ant-Veil

Caspar Blog

创建链接的问题:Symbol Links

| Comments

下了 NetBeans6.0 正式版的安装文件,没想到安装完毕在菜单项中居然不出现!一查看安装路径,执行脚本 netbeans 还在安安静静地躺在/usr/local/netbeans-6.0/bin 下面呢。于是准备创建链接。

因为刚才查找路径的时候已经进入 /usr/local/netbeans-6.0/bin 下了,所以想当然地执行了如下的命令:

ln -s netbeans /usr/bin
结果在 Terminal 下面输入 netbeans,无效,提示:Too many levels of symbolic links

一顿狂搜仍无结果……突然,意识到会不会是相对路径的问题,于是重新创建链接:

ln -sf /usr/local/netbeans-6.0/bin/netbeans /usr/bin
f 命令表示强制创建,覆盖同名文件。

这次终于成功了……

另外给一段关于 Symbol Link 和 Hard Link 的介绍:

A Hard Link is where a file has two names which are both on an equal weighting, and both of the file names in the "inode table" point directly to the blocks on the disc that contain the data. See diagram to the left.

You set up a hard link with an ln command without options - if the file ab.txt already exists and you want to give an additional name (hard link) to it, you'll write

ln ab.txt cd.txt

and then both names will have equal ranking. The only way you'll know that there's a link there is by doing a long listing and you'll see a link count of 2 rather than 1, and if you need to find out what's linked to what, use the -i option to ls.

A Symbolic Link is where a file has one main name, but there's an extra entry in the file name table that refers any accesses back to the main name. This is slighly slower at runtime that a hard link, but it's more flexible and much more often used in day to day admin work.

Symbolic links are set up using the ln command with the -s option - so for example

ln -s ab.txt cd.txt

will set up a new name cd.txt that points to the (existing) file ab.txt. If you do a log listing (ls -l) of a directory that contains a symbolic link, you'll be told that it's a symbolic link with an "l" in the first

其实一般创建的时候都用 Symbol Link 就行了。如果使用 Hard Link,一不小心删了链接,就对原文件造成了破坏。

Comments