0

I'm trying to change the modification timestamps using touch on a group of images that gets accessed by an external program that sorts them by modification date. The current mod times of these files are all exactly the same out to 9 digits, based on how they were created.

Can anyone suggest a way to use touch to change the modification time that's offset within the group of images? It could be offset by 1 min or 1 hour, doesn't matter. I just can't seem to get touch to do this. Am I using the write tool for the job?

Thanks.

0

The touch command is supposed to set a fixed time.

you can use a script:

#!/bin/bash

# get current time
start=$(date +%s)
# or get time of the first file
start=$(stat -c %X "$1")

for file; do
  touch -d @$start "$file"
  # increment by 1 second
  start=$((start + 1)
  # or by 1 minute
  start=$((start + 60)
done

Call the script with the list of files you want to change.

  • When I try this I get the following error: touch: invalid date format ‘@start’. I tried changing the time format but that doesn't seem to fix it... – Liam Sep 26 '18 at 14:22
  • Sorry, should have been @$start. – RalfFriedl Sep 27 '18 at 6:40

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.