MacOS – Copy range of files with same file structure

macosterminal

I would like to copy range of jpg files from the multiple folders.
I have a lot of folders with *.CR2 and *.xmp, in addition, it has a jpg folder with *.jpg files. I need to copy only jpg files and save file structure.
example:

2018/folder1/jpg –> temp/folder1/jpg
2018/folder2/jpg –> temp/folder2/jpg

Can this be automated? not to go to every folder and copy the files?
I tried Unix command:
cp folder1/*.jpg to folder1/jpg and got *.jpg: no such file or directory

Best Answer

I would like to copy range of jpg files from the multiple folders. I have a lot of folders with *.CR2 and *.xmp, in addition, it has a jpg folder with *.jpg files. I need to copy only jpg files and save file structure. example:

2018/folder1/jpg --> temp/folder1/jpg
2018/folder2/jpg --> temp/folder2/jpg

If I understand correctly what you're asking...

You can change directory into the 2018 directory, e.g.:

cd "/path/to/2018"

Then use, e.g.:

rsync -aR */jpg ../temp/

This will copy the folder*/jpg directories in 2018 to temp so you'll have temp/folder*/jpg directories, where temp it at the same level as the 2018 directory.

In other words, as in your examples:

2018/folder1/jpg --> temp/folder1/jpg
2018/folder2/jpg --> temp/folder2/jpg

They will be created as you've shown.