1

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.

1 Answer 1

1

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.

3
  • 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... Commented Sep 26, 2018 at 14:22
  • Sorry, should have been @$start. Commented Sep 27, 2018 at 6:40
  • start=$(stat -c "%Y" "$1") is correct. %X is atime, %Y is mtime Commented Jul 7, 2022 at 12:00

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.