Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
share|improve this question
up vote 6 down vote accepted

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.

share|improve this answer
That's perfect. I'm trying to improve my bash knowledge while writing a script that creates date based folders for the images and renames the files appropriately like you mentioned. – apparat Mar 14 '11 at 22:12
set -- $(exiv2 -g Exif.Image.DateTime -Pv DSC_01234.NEF)
year=$1; month=$2; day=$3; hour=$4; minute=$5; second=$6;
echo "$year:$month:$day $hour:$minute:$second"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.