Skip to content

Instantly share code, notes, and snippets.

@ibressler
Created June 16, 2019 18:10
Show Gist options
  • Save ibressler/fbf3ab797bb4b15d181b9b1d36846e80 to your computer and use it in GitHub Desktop.
Save ibressler/fbf3ab797bb4b15d181b9b1d36846e80 to your computer and use it in GitHub Desktop.
Rename iPhone pictures by embedded timestamp and associated MOV video files
for fn in *.JPG; do
echo "=> $fn"
# get the timestamp from exif, format it accordingly
ts=$(exiv2 -g DateTimeOriginal $fn | awk '{ts=$(NF-1)"_"$NF; gsub(":","",ts); print ts}')
# retrieve the base name as well
basen=${fn%.*}
# rename the image, append its original name
mv -i "$fn" "${ts}_$basen.jpg"
# check if there is video file with the same name (live mode)
if [ -f "$basen.MOV" ]; then
# rename the video file to the same timestamp
mv -i "$basen.MOV" "${ts}_$basen.mov"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment