Skip to content

Instantly share code, notes, and snippets.

@federicoB
Last active June 4, 2023 13:50
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Bash script for setting exif photo date according to filename. Created for whatsapp images can be easily adjusted for every filename patterns.
#!/bin/bash
set -e #Exit as soon as any line in the bash script fails
imageCounter=0
for filename in *.jpg
do
imageCounter=$((imageCounter+=1))
#extracting info from file name
year="${filename:4:4}"
month="${filename:8:2}"
day="${filename:10:2}"
#setting exif timestamp into file
exiv2 -M"set Exif.Image.DateTime $year:$month:$day" $filename
#set the file last modified timestamp
touch -t "$year$month$day""1500" $filename
done
echo "successfully set the correct timestamp in $imageCounter images"
@dileep-aapthitech
Copy link

Hi federicoB,

  • We need Storing session data in DynamoDB on Magento
    Please help me.

@nkuk377
Copy link

nkuk377 commented Dec 22, 2022

Hi.
I was trying to sort this problem out and found this code which helped me a lot. It worked like charm without changing anything.
I have 100-s of photos with right date-time on their names, but wrong in exif data.
I tried to modify this code to set the "time" stamp as in the photo's name, but could not make it work.
I stuck on error: "touch: invalid date format ‘20220412 200618’"
The example file I am trying this on is "IMG_20220412_200618.jpg"
I declared 3 more variables: $hour, $min, $sec, then tweak around, but no luck.
Please, give me a clue how to implement this.
Thanks for your code =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment