Question

By default, if you cp file from a place to another, the timestamp on the copied file is set to the time of copy. Is there some way to avoid this?

Answer

In Linux

The -p does the trick in Linux. -p is the same as --preserve=mode,ownership,timestamps.

cp -p <source_file_or_folder> <target_file_or_folder>

In FreeBSD

The -p also do the trick in FreeBSD. The -p cause cp to preserve the following attributes of each source file in the copy: modification time, access time, file flags, file mode, ACL, user ID, and group ID, as allowed by permissions.

In Mac OS

The -p also do the trick in Mac OS. The -p cause to to preserve the following attributes of each source file in the copy: modification time, access time, file flags, file mode, user ID, and group ID, as allowed by permissions. Access Control Lists (ACLs) and Extended Attributes (EAs), including resource forks, will also be preserved.

References & Resources

  • N/A