user3742929
user3742929

Reputation: 400

Create symlink with existing directory structure in new location

I'm using

find source -name 'Archive.folder'

which outputs:

source/1/Archive.folder
source/2/Archive.folder
...

to find all folders named Archive.folder in the source folder. Now I want to link them to a new location /var/CommuniGate/Accounts. How can I do that? I found the following solution but it doesn't work, it just links the source folder, not the found folders.

find source -name 'Archive.folder' | xargs -0 ln -s -t /var/CommuniGate/Accounts

The symlinks should be created like this:

/var/CommuniGate/Accounts/source/1/Archive.folder
/var/CommuniGate/Accounts/source/1/Archive.folder
...

Upvotes: 0

Views: 1101

Answers (1)

larsks
larsks

Reputation: 312750

Something like this, maybe:

find source -name Archive.folder -print0 |
xargs -0 -iDIR sh -c 'mkdir -p /var/CommuniGate/Accounts/$(dirname DIR); ln -s -t /var/CommuniGate/Accounts/$(dirname DIR) $PWD/DIR' 

That works for my simple test case.

Upvotes: 1

Related Questions