创建软件链接的语法如下:
link -s target linkName
实例:
ln -s ssh_connect_home link1
但是当我们想把此链接指向第二个文件时,结果却不如意料那般:
仔细一看:
原来这个命令将软件链接创建到目录中去了,这是为何?
参考一下man:
SYNOPSIS
ln [OPTION]... [-T] TARGET LINK_NAME (1st form)
ln [OPTION]... TARGET (2nd form)
ln [OPTION]... TARGET... DIRECTORY (3rd form)
ln [OPTION]... -t DIRECTORY TARGET... (4th form)
DESCRIPTION
In the 1st form, create a link to TARGET with the name LINK_NAME. In the 2nd form, create a link to TARGET in the current directory. In the 3rd and 4th forms, create links to each TARGET in
DIRECTORY. Create hard links by default, symbolic links with --symbolic. By default, each destination (name of new link) should not already exist. When creating hard links, each TARGET must
exist. Symbolic links can hold arbitrary text; if later resolved, a relative link is interpreted in relation to its parent directory.
原来,当链接文件已经存在时,被解析成了第三种格式,会在文件夹中创建到每个target的链接(链接名使用文件名)。
解决方法:
使用-n选项。
-n, --no-dereference
treat LINK_NAME as a normal file if it is a symbolic link to a directory
如果target是文件,则并不存在这种问题: