tinyapps.org / blog


Delete all files except... #

While importing a My Pictures directory from Windows XP into iPhoto via drag-and-drop, the process would crash after several thousand photos. I suspected iPhoto was choking on a non-JPG file, so I recursively deleted all other files in the directory:
Find all files but JPGs:
find . \( \! -iname "*\.jpg" \! -iname "*\.jpeg" -type f \) -print

Find all files but JPGs, and list them on one line:
find . \( \! -iname "*\.jpg" \! -iname "*\.jpeg" -type f \) -print0

Delete all files but JPGs:
find . \( \! -iname "*\.jpg" \! -iname "*\.jpeg" -type f \) -print0 | xargs -0 rm -f
Sure enough, after cleaning the directory of extraneous filetypes, the import worked flawlessly. Use the above commands at your own risk - unintended data loss is likely. As always: backup, backup, backup. (Thanks to Todd for his post, from which the above commands were largely lifted.)

/mac | Nov 15, 2007


Subscribe or visit the archives