Piping find to cp to recursively copy files

I have a bunch of font files organized within nested folders (along with all sorts of other stuff like text files).

I want to copy *just* the .ttf font files from within all of the folders. They need to be copied to a flat folder on my desktop that is named “Font Folder” (with spaces).

This turned out to be a lot more difficult than I originally anticipated, due to the fact that some of the files had spaces in their names. None of the guides or forum posts I found would work. I must have tried ten different “solutions” before I finally figured this one out. The key, as it turned out, was to enclose the {} in quotes:

find . -maxdepth 3 -type f -name \*.ttf -exec cp "{}" "/Users/tchapin/Desktop/Font Folder" \;

Leave a Reply

Your email address will not be published. Required fields are marked *

Are you a real person? *