How to change the creation (st_birthtime) date/time of a file in Lion? [duplicate]

touch(1) can only change modification and access times, but has no options for creation time. This does not work, at least not on Lion.

So how do I change the creation time, also referred to as birthtime in fstat(2)? There's no corresponding call in utimes(2) and there doesn't seem to be any command line tool for this.

I know I can copy the file to a new file, which then gets the current time as birthtime (and then delete the original), but surely there must be a better way?


touch -t also changes the creation time if the target modification time is before the original creation time.

SetFile can set the creation time to be before the modification time or in the future.

-d date    Sets the creation date, where date is a string of the
           form: "mm/dd/[yy]yy [hh:mm:[:ss] [AM | PM]]" Notes:
           Enclose the string in quotation marks if it contains spa-
           ces. The date must be in the Unix epoch, that is, between
           1/1/1970 and 1/18/2038. If the year is provided as a two-
           digit year, it is assumed to be in the 21st century and
           must be from 00 (2000) through 38 (2038).

This would set the creation time to the modification time:

SetFile -d "$(GetFileInfo -m test.txt)" test.txt

SetFile and GetFileInfo are part of the command line tools package, which can be downloaded from Xcode's preferences or developer.apple.com/downloads.