Skip to content

Instantly share code, notes, and snippets.

@slant
Last active August 26, 2016 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slant/84ab9528e2cecc03e88503a082af1eb6 to your computer and use it in GitHub Desktop.
Save slant/84ab9528e2cecc03e88503a082af1eb6 to your computer and use it in GitHub Desktop.
Redate image files with original exif data
# Set the date of picture files to the EXIF date
function redate () {
# Replace spaces in filenames with underscores
echo "Removing spaces..."
for file in *; do mv "$file" `echo $file | tr ' ' '_'` ; done
# Get orginal date from EXIF data and update file's metadata dates
# Required: http://www.sno.phy.queensu.ca/~phil/exiftool/
echo "Redating..."
find -E . -type f -iregex '.*\.(jpg|nef)' | while read PIC; do
echo "Redating $PIC"
DATE=$(exiftool -p '$DateTimeOriginal' $PIC | sed 's/[: ]//g')
echo "Date: $DATE"
echo "Command: touch -t $(echo $DATE | sed 's/\(..$\)/\.\1/') $PIC"
echo
touch -t $(echo $DATE | sed 's/\(..$\)/\.\1/') $PIC
done
}
@slant
Copy link
Author

slant commented Aug 26, 2016

This is necessary for pictures that are exported from an old Aperture or iPhoto or library. The file's Created and Modified datetimes are the date and time the pictures were exported. This script fixes that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment