macOS with APFS: Copy-On-Write in Terminal
Asked Answered
S

1

11

I am writing some little script that assembles backup data into one directory. The directory content will then be uploaded to a cloud service and after that we can remove it. I was wondering how one could utilize APFS' copy-on-write feature with a command like cp in Terminal.

The Finder does a great job. But if I run cp Largefile LargeFileCopy it takes forever to copy the file and also uses the space accordingly.

Sync answered 19/12, 2019 at 15:35 Comment(0)
S
18

I found it myself.

On macOS, cp supports the -c option. cp -c Largefile LargeFileCopy will then use the new clonefile(2) library and immediately return without using any additional space on the device.

Sync answered 19/12, 2019 at 15:35 Comment(3)
cp on macOS with APFS — Interesting that copy-on-write must be opted in with -c instead of being implicitly on as it is in the Finder. What were the design considerations behind this? Does anyone know?Foretopsail
May be it is meant to be POSIX compatible?Sync
Seems a plausible answer.Foretopsail

© 2022 - 2024 — McMap. All rights reserved.