What's an elegant way to copy the creation and modification dates of a file to another file?

How can I set the time information of a file to be the same as of another file on OSX / Linux?


Type:

touch -r FROMFILE TOFILE

That sets the access and modification times of TOFILE to match FROMFILE.

It will also update TOFILE's ctime to the current time.

There's no way to update the ctime (inode change time) to match another file, only to the current system time. (Which you can change if you really need to set the ctime, or use debugfs on an unmounted ext2/3/4 filesystem. See more on Stack Overflow)