当链接到另一个目录是由符号链接不工作? [英] Symlinks not working when link is made in another directory?

查看:100
本文介绍了当链接到另一个目录是由符号链接不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哇,我从来没有真正使用符号链接太多在这之前,但是这确实是令人难以置信的:

Wow, I've never really used symlinks that much before, but this is really boggling:

bash-3.2$ echo "weird" > original.txt
bash-3.2$ mkdir originals
bash-3.2$ mv original.txt originals/
bash-3.2$ cat originals/original.txt 
weird
bash-3.2$ mkdir copies
bash-3.2$ ln -s originals/original.txt copies/copy.txt
bash-3.2$ cat copies/copy.txt 
cat: copies/copy.txt: No such file or directory
bash-3.2$ ls copies/copy.txt 
copies/copy.txt
bash-3.2$ ls -l copies/copy.txt 
lrwxr-xr-x  1 zach  staff  22 Dec 22 01:23 copies/copy.txt -> originals/original.txt
bash-3.2$ cat originals/original.txt 
weird
bash-3.2$ cat copies/copy.txt 
cat: copies/copy.txt: No such file or directory
bash-3.2$ cd copies/
bash-3.2$ cat copy.txt 
cat: copy.txt: No such file or directory

为什么我不能猫在册目录符号链接?

Why can't I cat the symlink in the copies directory?

如果我使符号链接从副本里/,我可以猫它就好了。如果我做符号链接在当前目录下,我还可以猫它就好了。如果我做符号链接在当前目录下,然后将其移动到拷贝/,我得到复制/ copy.txt:没有这样的文件或目录。

If I make the symlink from inside the copies/, I can cat it just fine. If I make the symlink in the current directory, I can also cat it just fine. If I make the symlink in the current directory and then move it to copies/, I get "copies/copy.txt: No such file or directory".

推荐答案

如果您创建符号链接的相对路径,将其存储为一个相对的符号链接。符号链接是相对于位置的链接是,不是它被创建或打开的位置。

If you create a relative path to a symbolic link, it will store it as a relative symbolic link. Symbolic links are relative to the location the link is in, not the location where it was created or opened.

请使用绝对路径或相对路径的链接。

Please use absolute path or path relative to the link.

修改

ln -s originals/original.txt copies/copy.txt

要:

# absolute
ln -s /path/to/originals/original.txt copies/copy.txt

# relative
cd copies
ln -s ../originals/original.txt copy.txt

这篇关于当链接到另一个目录是由符号链接不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆