Find the answer to your Linux question:
Results 1 to 4 of 4
I'd like to change a files modification date "only" without changing the time. I'm aware of the 'touch' command but is seems like it only allows changing both the date ...
  1. #1
    Just Joined!
    Join Date
    Oct 2010
    Posts
    2

    Change file modification date without time

    I'd like to change a files modification date "only" without changing the time. I'm aware of the 'touch' command but is seems like it only allows changing both the date and time, and not one of them. Any ideas on an easy way to change a file's modification date without also changing its time? (I have a long list of files and thus would like to run one to command to change them all)

    Example: Change a file's (month) timestamp from "2010-09-23 11:59:23" to "2010-10-23 11:59:23"

    Background: I accidentally set the wrong month on my camera and ended up with all photos having a modification timestamp with the wrong month.

    Thanks.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,970
    Well, in the photo metadata (embedded in the image file) you will also have the wrong date as a result. So, just changing the file modification and/or creation date won't really help you all that much. In any case, I think you want the creation AND modification dates to be reset, not just the modification date. When a file is created, both are the same.

    In any case, you should be able to use either the --date=STRING or -t STAMP options of touch to change the access and modification date and/or time. I don't think you can change the creation date, except perhaps with custom C code. If so, I don't know precisely how to do that.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Oct 2010
    Posts
    2
    Rubberman: Thanks for the explanation, I wasn't considering the photo's metadata information! (that actually solved my main concern)

    I used 'exiv2' to change the metadata creation timestamp, and then used it to change the file's timestamp to match the metadata's timestamp:

    Example:
    To increment the metadata timestamp month by 1 (Sept. to Oct. for my case):
    > exiv2 -O 1 photo.jpg

    To change the file's timestamp to match the metadata:
    > exiv2 -T photo.jpg

    Thanks again!

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,970
    Cool! You just taught me something I didn't know, about using exiv2 to do this - I didn't have a clue, other than that the metdata would likely have the timestamp information along with other stuff.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...