Skip to content

Instantly share code, notes, and snippets.

@iandexter
Last active December 12, 2015 02:18
Show Gist options
  • Save iandexter/4697522 to your computer and use it in GitHub Desktop.
Save iandexter/4697522 to your computer and use it in GitHub Desktop.
Date a photo using EXIF timestamp.
for img in *.JPG ; do
fn=$(basename ${img} .JPG);
convert ${fn}.JPG ${fn}.exif;
tstamp=$(strings ${fn}.exif | grep -E "^[0-9]{3}.*\:.*" | head -1 | sed 's/:/\//' | sed 's/:/\//');
[[ -n "${tstamp}" ]] && tdate=$(date -d "${tstamp}" +"%d %b %Y %H:%M") || tdate="";
if [[ -n "${tdate}" ]] ; then
touch -d "${tdate}" ${fn}.JPG;
status="Touched"
else
status="";
fi
echo "${fn}.JPG ${tstamp} ${tdate} ${status}";
rm -f ${fn}.exif;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment