1

I have a bunch of files in a directory where the modification time was changed (incorrectly) with touch -m

The access time of these files is still close enough to what the modification time was, so I'd like to change them back.

Is there a way of doing a touch where it sets the mtime = atime? I don't want to set them all to the same timestamp, but I want to go file-by-file setting mtime = atime.

1 Answer 1

3

How about:

#!/bin/bash

for file in *; do
    # Get the access time using stat
    dateString=$(stat --format %x "$file")
    # Use the datestring to update the time with the 
    # access time
    touch -d "$dateString" "$file"
done

From man stat:

   %x     time of last access, human-readable

You must log in to answer this question.

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