ditto a folder but exclude some file types?

Is it possible to exclude a file type from transferring when using ditto?

For example, if my shell script ditto’s one folder to another location, and I want to exclude all .mp3 files, is that possible?

Thanks

(I thought about doing a find -name, moving those out of the folder, doing the ditto, then moving them back into the folder, but some mp3’s are nestled deep inside a game for example, and taking them out with a find would muck up that user’s game).

There’s no need to make it that complicated :slight_smile:

Use “find” to copy all files apart from the mp3s"

find . ! -iname "*.mp3" -exec cp {} /path/to/destination/folder ;

Regards

Ok, but what if I want to keep the folder structure the same, for example, if I move a user’s home folder, I don’t want to copy the .mp3’s, yet I don’t want all found files lumped into a single folder, I need to keep the heirarchy intact.

Thanks

Perhaps you can pipe the found data through to cpio?

Maybe something like:

find . ! -iname “*.mp3” -print | cpio -pmdv /path/to/folder

Which should retain the folder structure. I’m not able to test it at the moment - so use with care.

Cheers