How to change BSD’s file BIRTH time (aka btime)

filesosxtimestamps

BSD systems have utime(3) which (among other things) allows changing the "Birth time", aka btime (as compared to atime, mtime or ctime), of files. But, the man page also indicates utime(3) is obsoleted by utimes(2).

I know I can view the btime value using stat:

stat -f %B <file>

Unfortunately, it doesn't seem that touch(1) implements manipulation of btime. Man pages on my Mac include an entry for utime(3) in the C library which can manipulate btime, but I'm not seeing anything that provides an in-built interface to utime(3)'s btime manipulation.

Another hint that occurred to me: When I drag photos out of the Mac application "Photos", it creates new files. (The original files remain in their location where Photos keeps them organized, so I'm certain this is a new file copied from the original.) These new files have Created dates (what I see in finder listings or the get info, which display the btime value for the file) which match when the photos were taken — generally several years in the past. So clearly it is possible to set btime.

Best Answer

One way to solve this (this solves my problem) is to use Apple's SetFile(1) command which allows manipulation of file attributes. It takes a -d arg to manipulate creation date and a -m arg for manipulating modification time. Helpfully, if I set the modification time to before the current creation date, it sets the creation date too.

$ SetFile -m 05/14/200 foofile.jpg

This Q on the Apple/Think Different stack has this info https://apple.stackexchange.com/questions/49154/how-to-change-the-creation-st-birthtime-date-time-of-a-file-in-lion

Related Question