Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash touch - illegal option -d

Yesterday I took a bunch of pictures but I forgot to change the timezone in my camera. Now all pictures have wrong modification date.

I want to change modification date of all files in a specific directory to minus 10 hours.

#!/bin/sh
for i in /Users/slick/Desktop/100D5200/*; do
  touch -r "$i" -d '-10 hour' "$i"
done

When I run this script in OSX, I get

touch: illegal option -- d usage: touch [-A [-][[hh]mm]SS] [-acfhm] [-r file] [-t [[CC]YY]MMDDhhmm[.SS]] file ...

What am I doing wrong?

like image 960
Matt Komarnicki Avatar asked Nov 22 '25 12:11

Matt Komarnicki


2 Answers

You're using the options for GNU touch. You can install it in OS X using Homebrew in OS X:

$ brew install coreutils

Then it will be available under the name gtouch instead of touch:

#!/bin/sh
for i in /Users/slick/Desktop/100D5200/*; do
  gtouch -r "$i" -d '-10 hour' "$i"
done

However, the -d '10 hour' will not move the timestamp back ten hours, but set the timestamp to the current time minus ten hours. If you want to offset the time stamps, you will have to do the arithmetics for each file.

Furthermore, what you actually want might be to change the EXIF data of the pictures, which would need another tool than touch altogether.

like image 133
Dag Høidahl Avatar answered Nov 24 '25 02:11

Dag Høidahl


Below commands solved my problem:

exiftool "-AllDates-=10" /Users/slick/Desktop/100D5200
exiftool "-DateTimeOriginal>FileModifyDate" /Users/slick/Desktop/100D5200

Obviously before do

brew install exiftool
like image 23
Matt Komarnicki Avatar answered Nov 24 '25 02:11

Matt Komarnicki