简体   繁体   English

无法找到符号链接源项

[英]Symbolic link source item can't be found

I'm trying to make an alias of a directory in a set of directories 我正在尝试在一组目录中创建目录的别名

for D in $(find * -maxdepth 0 -type d) ; do
    ln -s location/to/directory/ $D/Test2 ;
done

It looks like the link is made correctly (I can see it in my finder window), but when I double click it, I get the error The operation can't be completed because the original item for "Test2" can't be found. 看起来链接是正确的(我可以在我的finder窗口中看到它),但是当我双击它时,我得到错误The operation can't be completed because the original item for "Test2" can't be found.

Why doesn't this work? 为什么这不起作用? Is there a way from a bash script to make a "normal" mac alias? 有没有办法从bash脚本制作“普通”mac别名? I have opened up the permissions, as suggested here , without any luck. 我已经打开了这里建议的权限,没有任何运气。

Use the absolute source path while creating the link. 创建链接时使用绝对源路径。 That worked for me having the same issue. 这对我有同样的问题。

You want to create a symbolic link called Test2 in each directory in the current directory, and each created link should point to location/to/directory . 您希望在当前目录的每个目录中创建名为Test2的符号链接,并且每个创建的链接应指向location/to/directory

for dir in */; do
    ln -s 'location/to/directory' "$dir/Test2"
done

The slash after * ensures that we will only match directories in the current directory, or links to directories in the current directory. *后面的斜杠确保我们只匹配当前目录中的目录,或者链接到当前目录中的目录。

If you're only interested in real directories an not symbolically linked directories, you may use 如果您只对真实目录感兴趣而不是符号链接的目录,您可以使用

find . -type d -mindepth 1 -maxdepth 1 \
    -exec ln -s 'location/to/directory' {}/Test2 ';'

Note that the link destination is relative to the location of the link, so if a directory does not contain location/to/directory , the link will be "dead". 请注意,链接目标是相对于链接的位置,因此如果目录不包含location/to/directory ,则链接将“死”。

You may solve this be specifying an absolute path for the links. 您可以通过指定链接的绝对路径来解决此问题。

What are you attempting to do? 你想做什么?

Think of a link as a cp command. 链接视为cp命令。 Maybe that will help: 也许这会有所帮助:

# Copies the 'svnadmin' command from /opt/svn/bin to /usr/local/bin
$ cp /opt/svn/bin/svnadmin /usr/local/bin

# Links the 'svnadmin' command from /opt/svn/bin to /usr/local/bin
$ ln -s /opt/svn/bin/svnadmin /usr/local/bin

Note that the ln and cp command have the same order of files. 请注意, lncp命令具有相同的文件顺序。

In your command, you're linking whatever location/to/directory/ to $D/test2 over and over again. 在您的命令中,您将一遍又一遍地将任何location/to/directory/$D/test2

Also, -maxdepth 0 won't be in the first level of the directory. 此外, -maxdepth 0将不在目录的第一级。

I use ln when I install new software, and the binary commands are in some other directory. 我在安装新软件时使用ln ,而二进制命令在其他目录中。 Instead of building on $PATH to include all of these extra directories, I symbolically link them to /usr/local/bin : 我没有在$PATH上构建包含所有这些额外目录,而是象征性地将它们链接到/usr/local/bin

$ cd /usr/share/apache-ant/bin
$ for file in *
> do
>     [[ -f $file ]] || continue
>     ln -s $PWD/$file /usr/local/bin/$file
> done

Note that the link simply copies the entire reference for the first file to the link. 请注意,链接只是将第一个文件的整个引用复制到链接。 I want to make sure that this link works everywhere, so I prefix that $PWD in front of it. 我想确保这个链接无处不在,所以我在它前面$PWD This way, my links look like this: 这样,我的链接看起来像这样:

$ ls -l ant
lrwxr-xr-x  1 root  wheel  29 Sep  3  2014 ant -> /usr/share/apache-ant/bin/ant

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM