1

My directory tree looks somewhat like this:

/Volumes/Data/TEMP/DROP
├───R1
│   ├───morestuff
│   │   └───stuff2
│   │       └───C.tool
│   └───stuff
│       ├───A.tool
│       └───B.Tool
└───R2
    ├───morestuff
    │   └───stuff2
    │       └───C.tool
    └───stuff
        ├───A.tool
        └───B.Tool

How do I copy the *.tool directories recursively from R1 to (overwrite) those in R2? My bash has about 20 years of rust on it.

Jetchisel
  • 7,493
  • 2
  • 19
  • 18
B.McKee
  • 328
  • 1
  • 2
  • 15
  • 2
    https://stackoverflow.com/questions/61104639/recursive-copy-files-in-bash-preserving-dir-tree see the edit-part on my answer `find /Volumes/Data/TEMP/DROP/R1 -type d -iname "*.tool" -exec cp -a --parents {} /Volumes/Data/TEMP/DROP/R2 \;` – alecxs Apr 09 '20 at 21:16
  • 1
    Use `rsync` with an exclude filter, see http://man7.org/linux/man-pages/man1/rsync.1.html#INCLUDE/EXCLUDE_PATTERN_RULES – Maxim Egorushkin Apr 09 '20 at 21:26

1 Answers1

1

This will work (expanding on the idea of @Maxim Egorushkin)


# The trailing slash important in the next line
SOURCE=/Volumes/Data/TEMP/DROP/R1/
DEST=/Volumes/Data/TEMP/DROP/R2
rsync -zarv --include "*/" --include="*.tool" --exclude="*" "$SOURCE" "$DEST"


Mamun
  • 2,322
  • 4
  • 27
  • 41