How to skip files with ditto command line utility? I'm trying to import a large (100GB+) iPhoto library located on a seemingly faulty external drive, that always yields an error -36 when I attempt to copy the library using Finder. I therefore tried the ditto the approach suggested in this article:

ditto -v ~/Pictures/Photos\ Library.photoslibrary/ /Volumes/MyDrive/Photos\ Library.photoslibrary/


The problem is, when ditto reaches the faulty file, I get these errors logged:


  ditto: (...)/MVI_5490.MOV: Device not configured
  
  ditto: (...)/IMG_5489.JPG: No such file or directory


Then suddenly macOS complains about the drive being ejected improperly, and the copy stops.

These two files seem to have contiguous IDs and reside in the same directory. So I guess that they're both located on a single faulty block.

I'd like to try preventing ditto from attempting to copy these files altogether, in the hope that this will prevent the disk from failing and allow the copy to complete (I don't care about a couple photos/videos missing, and I can always rebuild the iPhoto library later on).

Is there a way to instruct ditto to skip a known list of files?

If not, I'd accept an alternative solution (cp command based or any other), as long as it can handle the copy the way ditto does it (preserving ownership, permissions and such).
I've worked around the problem by booting on the failing drive and copying to the external drive.

I still get the I/O errors when attempting to read the same files, but at least the drive does not eject (and the system does not crash) so I was able to go through with ditto and ignoring/logging files in error.



Otherwise, the answer to my original question seems to lie with rsync:

rsync -av --exclude='path1/to/exclude' --exclude='path2/to/exclude' source destination


or:

rsync -av --exclude-from=FILE source destination


See this answer for more information.