Search code examples
macosshelldatetouchosx-snow-leopard

Subtracting time from file creation/modification date in OSX


I am trying to shift the dates of a series of files by 9 hours. I've reached as far as this:

for i in *.MOV; do touch -r "$i" -d "-9 hours" "$i"; done

This should work in recent systems, but the touch command in OSX seems to be a bit outdated and not to support the -d switch.

I'm using Snow Leopard. Any idea on the best option for doing this with a single line command? I don't want to create a script for this.


Solution

  • Ok, sorted it out. OSX comes with a gtouch command, that knows the -d switch. It's part of GNU coreutils. See the comments below for information regarding availability on specific MacOS versions.

    For more information on using relative dates with the -d switch see the manual.