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

1

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?

Ondra Žižka

Posted 2014-11-23T17:21:25.003

Reputation: 619

Answers

0

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.

anubhava

Posted 2014-11-23T17:21:25.003

Reputation: 930

0

Linux cp only makes symbolic links for the current directory, that means it will not link any files under subdirectories in the source path.

A script should be the answer, but this article may be helpful too.

Jose Rey

Posted 2014-11-23T17:21:25.003

Reputation: