Search code examples
bashfor-loopfindln

Create Symlink from recursive search in a certain folder


I want to create Symlinks for a recursive find search. This should also work for folders containing spaces.

The Symlinks should get created in a certain folder.

I tried to use this script:

IFS=$'\n'
for t in $(find . -type d -name "*search*" | sed 's|.*/||'); do
    ln -s "$t" "./symlink-folder/$t"
done

the problem is that the full path of the files does not get passed to ln, so the links created are all broken.


Solution

  • ok, seems like I made it running with:

    cd ./symlink-folder/
    find ../ -type d -name "*search*" -exec ln -s {} . ';'
    

    it does work with spaces