我可以将多个目录符号链接为一个吗? [英] Can I symlink multiple directories into one?

查看:28
本文介绍了我可以将多个目录符号链接为一个吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种感觉,我已经知道了这个问题的答案,但我想我会检查一下.

I have a feeling that I already know the answer to this one, but I thought I'd check.

我有许多不同的文件夹:

I have a number of different folders:

images_a/
images_b/
images_c/

我可以创建某种符号链接,以便这个新目录包含所有这些目录的内容吗?也就是说,这个新的images_all"将包含 images_aimages_bimages_c 中的所有文件?

Can I create some sort of symlink such that this new directory has the contents of all those directories? That is this new "images_all" would contain all the files in images_a, images_b and images_c?

推荐答案

没有.您必须以符号方式链接所有单个文件.

No. You would have to symbolically link all the individual files.

可以做的是创建一个定期运行的作业,它基本上删除了 images_all 中所有现有的符号链接,然后为所有文件重新创建链接来自其他三个目录,但有点混乱,如下所示:

What you could do is to create a job to run periodically which basically removed all of the existing symbolic links in images_all, then re-create the links for all files from the three other directories, but it's a bit of a kludge, something like this:

rm -f images_all/*
for i in images_[abc]/* ; do; ln -s $i images_all/$(basename $i) ; done

请注意,当此作业正在运行时,其他进程可能会认为文件暂时消失了.

Note that, while this job is running, it may appear to other processes that the files have temporarily disappeared.

您还需要注意两个或多个目录中存在单个文件名的情况.

You will also need to watch out for the case where a single file name exists in two or more of the directories.

过了一会儿又回到这个问题,我也想到你可以最大限度地减少文件不可用的时间.

Having come back to this question after a while, it also occurs to me that you can minimise the time during which the files are not available.

如果你将它们链接到一个不同的目录,那么就进行相对较快的mv操作,这样可以最大限度地减少时间.类似的东西:

If you link them to a different directory then do relatively fast mv operations that would minimise the time. Something like:

mkdir images_new
for i in images_[abc]/* ; do
    ln -s $i images_new/$(basename $i)
done

# These next two commands are the minimal-time switchover.
mv images_all images_old
mv images_new images_all

rm -rf images_old

我还没有测试过,所以任何实施它的人都必须确认是否合适.

I haven't tested that so anyone implementing it will have to confirm the suitability or otherwise.

这篇关于我可以将多个目录符号链接为一个吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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