MacOS – Search files across folders and move recursively to new folder

command linemacmacosphotosterminal

I need a way to search from a base folder, all the folders inside of that one recursively, and find all photos of JPG and PNG that were created before a certain date (01.Feb.2013) and then move them to a particular folder.

How would I go about this?

Best Answer

You could use find:

touch -t 201302010000 /tmp/a
find ~/directory \( -iname \*.jpg -o -iname \*.png \) -Bnewer /tmp/a \
    -exec mv {} ~/directory2 \;

touch -t normally changes only the modification and access times, but it also changes the creation time if the target time is before the original creation time or when you are creating a new file.

-Bnewer (for birth time / creation time) is not supported by GNU/Linux platforms which don't have metadata for the creation time.

The parentheses are needed because -a (and concatenating expressions without -a) has higher precedence than -o.