9

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.

Anticro
  • 685
  • 4
  • 12

1 Answers1

16

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.

Anticro
  • 685
  • 4
  • 12
  • **`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? – porg Mar 10 '23 at 10:35
  • 1
    May be it is meant to be POSIX compatible? – Anticro Mar 13 '23 at 17:41
  • Seems a plausible answer. – porg Mar 19 '23 at 19:10