Copy directory structure and symlink files (alternative to `cp -as`)

Solution 1:

The GNU version of cp is part of coreutils

brew install coreutils

It gets installed as gcp to avoid conflicts with the BSD version of cp (which behaves differently for some arguments).

Solution 2:

If you are on APFS - I would use ditto which preserves all the metadata, understands APFS transparent compression and handles all of the native items as well as POSIX items like suid/sgid

  • https://stackoverflow.com/questions/40974029/what-is-difference-between-cp-and-ditto-command-on-osx
  • How do I transparently compress a directory?

This will save you headaches with tools that don’t preserve code signing, notarization, quarantine bits and more when those all become mandatory in future releases.

  • https://eclecticlight.co/2019/11/12/preparing-for-new-security-rules-how-signatures-can-get-stripped/