Skip to main content
2 of 3
added 11 characters in body

Find directory matching a specific name and recursively copy from the parent-dir of find search-results

I have a directory structure like this: m/n/o/p/q/r/s/t.

I want to find directories that match by name "r" and copy contents recursively from the parent-dir of the find-result (ie. "q/r/s/t" in this case) onto another location.

Something like:

find m/n/o/p -type d -name "r" -exec cp -r "../{}" /<folder_to_copy_into> \; 

I've tried experimenting with -printf %h and -maxdepth, but I'm not sure I have the correct syntax. I'm not sure if I should be piping into another find to get my intended result. (Goal is to only copy from one-parent-dir-above-from-find-results recursively into the other dir location).

As long as I can find dir named "r", I want to recursively copy everything from r's parent-dir onto a new dir-location. (eg: if I have m/n/o/p/q/r/s/t, I want "q/r/s/t" to be recursively copied onto the new dir-location).