Easiest way to find and copy all all JPEGs on a Mac to a new folder
May 30, 2015 2:36 PM   Subscribe

I'd like to find and copy all image files on my MacBook Air and an external hard drive that copy them all to a new folder on the external hard drive.

Finding them is no problem w/ search and Smart Folders, but the Finder chokes when I attempt to drag 44k files to a new window. If I could turn the Smart Folder into a "real" folder, that would work, but I can't seem to find a way to do that. I can't get any of the Terminal instructions I find elsewhere on the Web to work for me. Please help!
posted by ndg to Computers & Internet (6 answers total) 6 users marked this as a favorite
 
This command will make a list of all the JPG and JPEG files and save it in /tmp/jpg-list:
find /folder-to-start-looking-in -type f -print | egrep -i '(jpg|jpeg)$' > /tmp/jpg-list
This command will read the list of files and copy them to the destination folder:
cpio -pvdm "/Volumes/External Disk/Destination Folder" < /tmp/jpg-list
HTH.
posted by spacewrench at 2:49 PM on May 30, 2015 [1 favorite]


Best answer: You should be able to accomplish this just using find:
find /path/to/look/through -type f -name "*jpg" -exec cp {} /path/to/backup/folder/ \;
Start that, go get a cup of coffee. Repeat with "*jpeg" if you have files with that extension.
posted by axiom at 3:08 PM on May 30, 2015 [1 favorite]


In your title you say all JPEGs but in the body of your post you say all images, and I bet you mean the latter. So I'm going to add a couple of items to spacewrench's first line to be more complete and also include PNGs and GIFs:
find /folder-to-start-looking-in -type f -print | egrep -i '(jpg|jpeg|png|gif)$' > /tmp/jpg-list

posted by foxfirefey at 3:14 PM on May 30, 2015


Response by poster: Thank you all!
posted by ndg at 4:01 PM on May 30, 2015


I just thought to add: this will only work right if you don't have name collisions (i.e., two files in different folders with the same name, like IMG0001.JPG or whatnot). If you do, whichever one it encounters second will overwrite the first in the destination folder. You can use rsync to copy the directory structure and only the images within those directories if you want to avoid this problem (this may result in lots of empty directories, depending on how large a file tree you're copying from):
rsync -a --include='*.jpg' --include='*.jpeg' --include='*/' --exclude='*' /path/to/look/through/ /path/to/backup/folder/

posted by axiom at 4:29 PM on May 30, 2015 [1 favorite]


axiom: "this may result in lots of empty directories, depending on how large a file tree you're copying from"

rsync has an option to skip copying empty directories, so axiom's command would change to:
rsync -a --prune-empty-dirs --include='*.jpg' --include='*.jpeg' --include='*/' --exclude='*' /path/to/look/through/ /path/to/backup/folder/
(--prune-empty-dirs can also be expressed as -m , but that's not as easy to remember.)
posted by double block and bleed at 5:14 PM on January 9, 2016


« Older Your favorite non-US interview podcasts/radio...   |   How can I prevent my full garbage can from getting... Newer »
This thread is closed to new comments.