Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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?

share|improve this question
1  
touch -t yyyymmddhhmm $file does seem to change the creation date, but only if it's before the original creation date. –  Lauri Ranta Apr 20 '12 at 5:22
    
Good point, @Lri - that actually makes sense, since that updates the mtime and atime and a file couldn't be accessed or modified before it was created. But it doesn't let me set a newer creation time. –  Ingmar Hupp Apr 20 '12 at 13:32
    
Are you referring to changing it via the command line, or just in general, not necessarily with the CLI? –  daviesgeek Jun 29 '12 at 21:36
    
Frankly I would hope you can't change it, as surely it would defeat the entire point of the field?! Also I suspect some of hte problem is that birthtime/creation time isn't a standard filesystem feature; hfs added it in their extended attributes, I think - so unless utilities have been updated to recognise that, they won't be able to do much with it. –  Caesium Aug 2 '12 at 13:59
    
possible duplicate of How do I set the creation time of a file? –  patrix Aug 7 '12 at 20:11
add comment

2 Answers

up vote 4 down vote accepted

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.

share|improve this answer
add comment

Try:

cat filename > newfile
mv filename ~/.Trash/
mv newfile filename 

That should work.

share|improve this answer
1  
You'll still need to delete the original. Ingmar had already covered this. –  Hippo Apr 20 '12 at 1:53
    
Whoops, should've read better. But no, there is not a better way... –  Sean Freitag Apr 20 '12 at 3:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.