Linux/Bash: Create relative soft links to files in directory tree

bashhyperlinklinux

I'd like to make links to all files in a directory tree.
Which means, create the same directory structure and make the links in them to the respective subdirectory in the original dir.

That could be done with

cp -R -s ../foo .

But – that needs an absolute path. So rather

cp -R -s `readlink -e ../foo` `readlink -e .`

I would like the resulting links to be relative.

How would I do that?

Best Answer

You can put some more glob pattern in front of ../foo like this:

cp -R -s ../foo/* .

This will create relative symbolic links in current directory of all files/directories found in ../foo/* path.