Can I symlink multiple directories into one?

前端 未结 3 1330
温柔的废话
温柔的废话 2020-12-28 13:50

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/
imag         


        
3条回答
  •  长发绾君心
    2020-12-28 14:07

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

    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.

    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.

提交回复
热议问题