MacOS – How to change all dates on file and preserve them during file move

filefilesystemmacos

I would like to change all dates on a file [all four reported by stat command].
I cannot find a way to change the "inode last changed" date.
I've tried:

touch -t
SetFile -d
SetFile -m

but this single date remains unchanged.

Also, is there any way to move file between directories and leave all of the dates intact?
I am moving whole directories, with lots of files inside, so I would prefer to have a single command to do so, if not – I will read the date upfront and set it after the move.

Best Answer

You cannot controlctime.ctime is set with the creation of the inode. ctime changes to the mtime when you modify a file. ctime is set to the current date and time when you modify the inode metadata, such as changing mtime, file permissions, or renaming a file.

The closest you can come to matching atime,mtime, and ctime would be totouch a file which will set all three to the current date and time. But at anytime ctime may change, even OS X applications can cause changes to the inode metadata without changing the content of a file.

btime or birthtime will not change when moving files on the same filesystem.

Tools that support preserving file metadata are ditto, pax, and cp with the p option. None of these tools support preserving birthtime across filesystems.