how-to

Change a File’s Last Modified and Creation Dates on Mac OS X and Linux

Date Format Key:

  • YYYY — The year (the first two digits/century can be omitted).
  • MM — The month of the year, from 1 to 12.
  • DD — The day of the month, from 1 to 31.
  • hh — The hour of the day, from 0 to 23.
  • mm — The minute of the hour, from 0 to 59.

Go to answer for Mac OS High Sierra

Go to answer for Mac OS El Capitan and older

How to change the “date modified” attribute of a file in Mac OS High Sierra?

Unfortunately, new versions of Mac OS have different version of touch command, try these steps:

1. Open up the Terminal application (/Applications/Utilities/Terminal.app) or if you prefer use iTerm.
2. Type this into Terminal (without hitting enter/return) replacing YYYYMMDDhhmm with the desired date information:

touch -m -t YYYYMMDDhhmm

3. Open a Finder window and locate the file you wish to modify and drag and drop it into the Terminal window. Here’s an example of what should be typed into the Terminal at this point:

touch -m -t 200801120000 /Volumes/Mac\ HD/Pictures/somefile.jpg

200801120000 in the example above represent “January 12, 2008 12:00 AM” or my 21st birthday. Make sure to change 200801120000 to the date you want and to replace /Volumes/Mac\ HD/Pictures/somefile.jpg with the proper path to the file you wish to alter the date for.

4. If all is in order press the return key.

How to change the “date modified” attribute recursively?

find ./folder/ -type f -exec touch -m -t 200801120000 {} \;

How to change creation date too?

Just remove m argument:

touch -t 200801120000

 

Alternatively, you can install xcode command line tools, and follow all steps:

xcode-select --install

Then you can use it’s command to change creation date, date syntax is MM/DD/YYYY HH:MM:SS (where HH is hours in 24h format):

setfile -d "02/28/2016 13:21:59" FILENAME.PNG

How to change the “date modified” attribute of a file in Mac OS El Capitan and older?

1. Open up the Terminal application (/Applications/Utilities/Terminal.app) or if you prefer use iTerm.
2. Type this into Terminal (without hitting enter/return) replacing YYYYMMDDhhmm with the desired date information:

touch -mtYYYYMMDDhhmm

3. Open a Finder window and locate the file you wish to modify and drag and drop it into the Terminal window. Here’s an example of what should be typed into the Terminal at this point:

touch -mt200801120000 /Volumes/Mac\ HD/Pictures/somefile.jpg

200801120000 in the example above represent “January 12, 2008 12:00 AM” or my 21st birthday. Make sure to change 200801120000 to the date you want and to replace /Volumes/Mac\ HD/Pictures/somefile.jpg with the proper path to the file you wish to alter the date for.

4. If all is in order press the return key.

How to change the “date modified” attribute recursively?

find ./folder/ -type f -exec touch -mt200801120000 {} \;

How to change creation date too?

Just remove m argument:

touch -t200801120000

What’s about Linux?

It’s the same but with additional space:

touch -mt YYYYMMDDhhmm

and recursive one:

find ./folder/ -type f -exec touch -mt 07011200 {} \;

17 thoughts on “Change a File’s Last Modified and Creation Dates on Mac OS X and Linux”

  1. I was just seeking this info for some time. After six hours of continuous Googleing, at last I got it in your web site. I wonder what is the lack of Google strategy that don’t rank this kind of informative websites in top of the list. Generally the top sites are full of garbage. gedegfedbege

    1. Sorry for late reply, but these commands can only change file system created and modified date. If you want to change video metadata – you need to use some video editor.

  2. Had a whole month of pics on my Mac with the wrong year originally set on camera. Been stumbling through confusing websites and youtubes before I found your clear explanation.

    Thanks!

  3. This does not work anymore. The terminal says “out of range or illegal time specification”. Any idea how to write the date nowadays 2018?

    1. Looks like there was some problem with date format you’ve specified.

      Could you give me the full command, which you wrote?

  4. im trying to change a file to “Date Created: 12. December 2017”

    I made this:
    touch -t201712120000/Users/espenostendorf/Desktop/Das\ Business\ Simulation\ Game\ ist\ eine\ Form\ des\ aktiven\ Lernens\ unter\ experimenteller\ Bedingungen.docx
    touch: out of range or illegal time specification: [[CC]YY]MMDDhhmm[.SS]

  5. Hi there,
    I am trying to change only the date modified but when I use touch -mt… it changes both the date created and date modified. Am I doing something wrong?
    Thanks

  6. Hi
    thanks for the clear explanations, I had the same problem (forget the space after the argument).
    however, after correction of the command, it works but it changes only the “date modified”, not the “date created”.
    here is my command:
    MacBook-Pro-de-Guillaume:~ Guillaume$ touch -t201807241100.00 /Users/Guillaume/Movies/2018-vacances\ été/GOPR0867.MP4
    I work on Mac OS High Sierra.
    I copied a file twice and tried with “touch – t” and “touch – mt” to see if I get something different, but in both cases, only the “date modified” is changed.
    Could you advise me how to change the creation date too?

    1. Please try to change date to something in future first, and after it change to needed one. Looks like new version of touch in Mac OS doesn’t work as expected.

  7. Hi there,

    I want to change the creation date to 1 month newer. And keep the other dates the same.

    I’m on mac 10.11.6

    Using terminal

    I’m inputting

    touch -t201612131507/Users/myname/Desktop/time/131.jpg

    I get this message back

    out of range or illegal time specification: [[CC]YY]MMDDhhmm[.SS]

    Any ideas?

    Thanks

    1. Hello James,

      you need to add a space between touch -t201612131507 and /Users/myname/Desktop/time/131.jpg, so your command should be: touch -t201612131507 /Users/myname/Desktop/time/131.jpg

Leave a Reply

Your email address will not be published. Required fields are marked *