Search code examples
directoryfindsymlinkcreation

How to create symlinks to all directories in folder(a) in folder(b)?


In some cases it might be desired to create symbolic links to all folders that are contained in one folder, e.g. folder(a) in another folder, e.g. folder(b). Linux offers strong command line functionality, so I thought that this can easily be done with find:

find folder\(a\)/ -maxdepth 1 -type d -exec ln -s {} \
    folder\(b\)/`echo {} | cut -d '/' -f2` \;

But this command doesn’t do it’s job. Which is the best way to do it?


Solution

  • Here is one way I found out it works:

    find folder\(a\)/ -mindepth 1 -maxdepth 1 -type d \
        -printf 'ln -s "../%p" folder\\(b\\)/%f\n' | sh