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?


1 Answer 1


The touch command is supposed to set a fixed time.

you can use a script:


# 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)

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .