Exif Data – How to Print Specific Exif Image Data Values with Exiv2

bashexifregular expressionshell

How do I print the image Exif date with a tool like exiv2?

My goal is to write the image year and month into separate variables. Do I really have to parse the output with regex or is there a alternative to something like this:

exiv2 DSC_01234.NEF -ps | grep 'Image timestamp' | ...regex to parse the date

Best Answer

You can use the -g flag to output only the property you're interested in, and -Pv to print the value without any surrounding fluff. The result is easy to parse.

IFS=': '
set $(exiv2 -g Exif.Image.DateTime -Pv DSC_01234.NEF)
unset IFS
year=$1 month=$2 day=$3 hour=$4 minute=$5 second=$6

It may also be helpful to change the file date to match the image date: exiv2 -T DSC_01234.NEF.

Related Question