The transfer of images from IPhone somehow screwed up the file dates. I want to set them from EXIF data.

I already found a solution but wasn't able to convert this into a batch job. Feel free to help, maybe other users find it useful.

find . -type f -iname "*.jpg" -print0 | xargs -0 -n1 -I % sh -c 'touch % -d "$(file %|grep -oP "datetime=\K[^,]*"|sed -e "s/:/-/"|sed -e "s/:/-/")"'

I solved it with this command.

identify -verbose <file> |egrep "Image:|exif:DateTimeDigitized:" |sed '{N;s,Image: \(.*\)\n.*exif:DateTimeDigitized: \(.*\),touch -d "\2" \1,}'|sed 's,2017:10:,2017-10-,'

I wasn't able to convert this into a batch job because sed is required to work on multi-lines which collides somehow with different approaches working on a list (xargs, a simple list...)

Just pipe it to bash to execute or copy & paste.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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