Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move specific folders to a new location and leave a symlink at the old location to the new folder

Tags:

find

shell

cp

mv

I have a lot of folders named Archive.folder in /var/CommuniGate/Accounts/*/. How can I move them to a new location and leave a symlink at the old folder to the new location?

Maybe use find and cp to move them?

find /var/CommuniGate/Accounts/ -name 'Archive.folder' -exec cp -r --parents {} . \;

This works fine for moving them and keeping the folder structure. But how can leave a link at the same time with ln? Also the link should replace the old folder.

I've tried executing the following after, it works if there is only one folder.

find /var/CommuniGate/Accounts/ -name 'Archive.folder' -delete

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

I get permission denied for the sh -c for everything after the first directory.

like image 313
user3742929 Avatar asked Oct 19 '25 01:10

user3742929


1 Answers

You can juste move your file to the desired location and then create the symlink :

  • mv /var/CommuniGate/Accounts/Archive.folder* new_location/
  • ln -s new_location/Archive.folder* .
like image 171
A. Ecrubit Avatar answered Oct 22 '25 04:10

A. Ecrubit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!