Skip to content

Instantly share code, notes, and snippets.

@nicnocquee
Created January 13, 2016 10:32
Show Gist options
  • Save nicnocquee/5a24bd6ac8b92cceab33 to your computer and use it in GitHub Desktop.
Save nicnocquee/5a24bd6ac8b92cceab33 to your computer and use it in GitHub Desktop.
Script to organize photos by grouping them into folders of year and month of date taken. Requires imagemagick.
#!/bin/sh
function readImage () {
if [ "$1" != "." ] ; then
DIRTOMAKE=`identify -verbose "$1" | grep exif:DateTime: | sed 's/exif\:DateTime\: //g' | sed 's/\:[0-9][0-9] [0-9][0-9]\:[0-9][0-9]\:[0-9][0-9]//g' | sed 's|:|/|g'`
trimmed=`echo "$DIRTOMAKE" | xargs`
if [ -z "$trimmed" ] ; then
trimmed="Unknown"
fi
echo "Moving $1 to $trimmed ..."
mkdir -p "${trimmed}"
mv -n "$1" "${trimmed}"
fi
}
export -f readImage
find "$1" -maxdepth 1 -iregex ".*\.[PNG|JPG|jpeg]*" -execdir bash -c 'readImage "$0"' {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment