找不到软 link,即使它显然存在

Soft link is not found, even though it's clearly there

首先,我创建了一个指向可执行文件 mesher 的软链接,并确认它确实存在:

[me@mine mesh_subdir] ln -s mesher ../mesher
[me@mine mesh_subdir] cd ../
[me@mine project_home] ls
file1 file2 mesher

看起来不错。

现在,我想执行 mesher:

[me@mine project_home] ./mesher
-bash: ./mesher: No such file or directory

为什么?我清楚地看到 project_home 中有一个文件 mesher。我还尝试按两次 Tab 以查看所有选项,但 mesher 从未出现。与此同时,file1file2 上的 cat 正常工作。

为什么在我的文件系统中找不到 mesher,我该怎么办?

(这是 bash shell 在 OS X Sierra 上。)

因为它是相对于目标创建的:

ln -s dirname/mesher ../mesher

也 ls -l 显示损坏 link

cd ..
ls -l mesher

Symlinks 可以有相对路径。 ln -s mesher ../mesher 行的意思是“在 ../mesher 中创建一个 symlink 到当前目录中名为 mesher 的文件。现在,当您执行 cd .. 时,当前目录更改 -- 更改 link.

的目标

尝试 ls -l mesher 而不是 ls,您会发现问题所在:mesher symlink 指向自身。

相反尝试:从 symlink 应该驻留的目录链接:

cd ..
ln -s mesh_subdir/mesher mesher

顺便说一句,如果源和目标具有相同的名称,您可以省略 link 的名称:ln -s mesh_subdir/mesher 就足够了。