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


How about:


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"

From man stat:

   %x     time of last access, human-readable

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.