Skip to content

Instantly share code, notes, and snippets.

@mattrasband
Created December 10, 2013 21:52
Show Gist options
  • Save mattrasband/7900909 to your computer and use it in GitHub Desktop.
Save mattrasband/7900909 to your computer and use it in GitHub Desktop.
Automatically sort images into folders based on their EXIF data.
#!/usr/bin/env bash
SRC=${1:-"/mnt/camSD"}
DEST=${2:-"/home/`whoami`/Pictures"}
EXT=${3:-"jpg"}
#UUID=null # Get UUID with `blkid /dev/sdX#`
function checkResources {
if [ ! -L "/dev/disk/by-uuid/${UUID}" ]; then
echo "The disc is not mounted, the process will halt."
exit
fi
}
function moveImages {
for img in `find ${SRC} -maxdepth 1 -type f -name "*.${EXT}"`; do
echo "Found Image: ${img}"
subDEST=`identify -verbose ${img} | awk '/exif:DateTimeOriginal:/ {print $2}' | sed 's_:_/_g'`
if [ ! -d ${DEST}${subDEST} ]; then
echo "The destination doesn't exist... making directory ${DEST}${subDEST}"
mkdir -p ${DEST}${subDEST}
fi
echo "Moving ${img} to ${DEST}${subDEST}"
mv ${img} ${DEST}${subDEST}
done
sync
echo "Finished."
}
#checkResources
moveImages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment