File Dates – How to Copy Creation and Modification Dates of a File to Another File

bashlinuxmacos

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

Best Answer

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)

Related Question