I’m sure your recommendation to use ditto instead of cp is a good one, but cp has preserved resource forks for over a decade. So that is for BSD like systems, i.e. FreeBSD, OpenBSD and Mac OS X. I use the following command: sudo cp -va --preserve=all 2nd/. It was a long time ago, but it may have been around 10.1. Ex: replace ssh host keys cp --no-preserve=mode,ownership ssh* /etc/ssh/.
cp -pPR-p = preserve -R = recursive -P = no symbolic links are followed -- can be added but this is the default behavior The man page for cp says this about the -a option: Same as -pPR options.
On Linux systems:-p same as —preserve=mode,ownership,timestamps —preserve[=ATTR_LIST] 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. FreeBSD cp's manual does not have this caveat, although the structure of the options remains very similar, if not identical. If not specified, the default value of attr_list is "mode,ownership,timestamps".--no-preserve=attr_list Don't preserve the specified attributes.--parents: Create missing parent directories in the destination, if necessary, when copying to target directory, according to the pathname specified in source. If you want to copy files in Linux and also want to keep or preserve the original mode or timestamp or ownership (or all) , cp command gives an option (--preserve).
According to the cp man page cp -a is the same as cp -dpR which is-p = preserve mode,ownership,timestamps -R = recursive -d = no dereference and preserve links The OS X equivalent would be. Linux - copy file and preserve timestamp, ownership, mode. Preserves structure and attributes of files but not directory structure. I am trying to copy data back onto an sd card with an ext2 type partition whilst preserving the ownership and permissions. What does not preserving directory structure mean in this case? I remember Apple first offered a version of cp that ignored resource forks, then offered a version called cp_mac that handled resource forks. By 10.2 or 3, the regular cp copied resource forks with no problem. – basin Oct 2 '18 at 9:20 The man page's --preserve explanation is IMHO nonsensical as it does not make it clear preserve what: The source or target attributes – Waslap Feb 22 '19 at 12:40 This makes the secret keys world-readable.