2

I want to share 10K photos using Google Photos. These images were scanned, so they don't have correct DateTimeOriginal for chronological ordering.

I need to update DateTimeOriginal to YYYY:01:01 00:00:00 to allow me to organize these within Google Photos for sharing and having some sense of order. My understanding is Google uses exif DateTimeOriginal for sorting.

My photo naming conventions:

1967 Smith G & J Wedding - 3.jpg

1962 Smith Family Reunion - 87.jpeg

1990 Smith 50th Anniversary - 16.jpeg

I tried this:

exiftool "-datetimeoriginal < ${filename;$_=substr($_,0,3)} 01:01 12:00:00" DIR

but receive a BASH "bad substitution error"

Any assistance would be appreciated.

Grinnz
  • 9,093
  • 11
  • 18
  • The shell will interpret `$` variables in a double quoted string. Try single quoting the code you pass. – Grinnz Jan 30 '19 at 20:50

2 Answers2

3

There may be a better way, but this works:

#!/bin/bash
for f in *.jpg; do
   year=$(grep -Eo "^\d+" <<< "$f")
   echo File: $f, setting year:$year
   exiftool "-datetimeoriginal=${year}01:01 12:00:00" "$f"
done

Debug Output

File: 2013 Family Reunion.jpg, setting year:2013
    1 image files updated
File: 2017 Some wedding.jpg, setting year:2017
    1 image files updated

Try it on a COPY of your files in a temporary directory!

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
2

You're close with your original, but as @Grinnz said, you need to use single quotes. Additionally, you want the first 4 numbers for the year, but you're only grabbing 3.

So try:
exiftool '-DateTimeOriginal<${filename;$_=substr($_,0,4)} 01:01 12:00:00' FileOrDir

The startup time of exiftool is its biggest performance hit, so you'll find this is much faster than looping over each file (see exiftool Common Mistake #3).

This command creates backup files. Add -overwrite_original to suppress the creation of backup files. Add -r to recurse into subdirectories.

StarGeek
  • 4,948
  • 2
  • 19
  • 30
  • This is much faster than looping provided above. 10k images using loop took 10minutes. exiftool native took 1 minute for 10k images. Thanks this is the best answer. I appreciate Mark's answer too! – justonetaste2003 Feb 01 '19 at 20:14