Get the latest tech news
Create space-saving clones on macOS with Python
You can shell out to `cp -c` using `subprocess`, or you can make a `clonefile()` syscall using the `ctypes` library.
APFS uses a technique called copy-on-write to store the data efficiently on disk – the cloned files continue to share any pieces they have in common. In my project, I wrapped this cp call in a function which had some additional checks to spot common types of error, and throw them as more specific exceptions. The exception includes the numeric error code, and Python will throw named subclasses of OSError like FileNotFoundError, FileExistsError, or PermissionError.
Or read this on Hacker News