I want to copy (overwrite) folders from one directory to another set of directories, only if the folders in directory1 exist in directory2.
For example, I have stored some folders in my home directory:
home |admin |updates |package1 |package2 |package3
I also have another folder with builds of an app:
home |builds |build1 |packages |package1 |package2 |package3 |build2 |packages |package1 |package3 |build3 |rev1 |packages |package1 |rev2 |packages |package2
I want the 'package1', 'package2', 'package3' folders found in '/home/updates/package' directory to be copied over to the 'packages' folders found recursively in '/home/builds' directory, but only if the folders already exist.
So in the example above, 'package1'/'package2'/'package3' would be copied into '/home/builds/build1/packages'. Only 'package1' would be copied into '/home/builds/build3/rev1/packages' ('package2'/'package3' would not because it doesn't exist there).
In addition, 'build1'/'build2'/'build3' may have different owner/group permissions so I would like to retain the relative target directory's permissions.