cp --reflink=auto
shows following output for MacOS:
cp: illegal option -- -
Is copy-on-write or deduplication supported for HFS? How can I COW huge files with HFS?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communitycp --reflink=auto
shows following output for MacOS:
cp: illegal option -- -
Is copy-on-write or deduplication supported for HFS? How can I COW huge files with HFS?
Apple's new APFS filesystem supports copy-on-write; CoW is automatically enabled in Finder copy operations where available, and when using cp -c
on the command line.
Unfortunately, cp -c
is equivalent to cp --reflink=always
(not auto
), and will fail when copy-on-write is not possible with
cp: somefile: clonefile failed: Operation not supported
I'm not aware of a way to get auto
behavior. You could make a shell script or function with automatic fallback a la
cpclone() { cp -c "$@" || cp "$@"; }
but it'll be difficult to make it entirely reliable for all edge cases.
Updated November 2021: This answer has been rendered obsolete by oncoming coreutils changes. reflink=auto has been the default since 25725f9 (coreutils 9.0). APFS cloning is committed in the tree as 5e36c0c and should appear in coreutils 9.1.
Original posting November 2019: I wrote a patch (mailing list) for GNU coreutils that enables --reflink
for macOS > 10.12. Yes, --reflink=auto
will work, at least according to my time measurements.
Here are two ways to use it:
./bootstrap
, and then the usual ./configure -C
and make -j12 install
.You can grab a bunch of possible parameters to use from the homebrew formula. Since the change is only useful for cp
and mv
only, you can opt to only replace these two binaries. (mv
with reflink is useful for submodules.)
There is an associated patch that enables reflink=auto by default for cp
and install
too. If you keep forgetting about adding the option or want faster ginstall
in your Makefiles, try it.
Unfortunately the --reflink=auto
option wasn't available in MacOS just yet. HFS also does not natively support CoW (Copy on Write).
Perhaps in future such support will be added - likely when ZFS becomes natively available or another native filesystem adds support.
I suggest referring to the man page to get the options that are currently available to you: man cp
NOTE:
In MacOS, most commands (including cp
) only support short options, not long options. Thus, if there were an equivalent, it would be a single character only. Example would be -L
or --dereference
available in GNU coreutils' version of cp
. In MacOS, only -L
is available.
uutils is a GNU coreutils clone written in Rust and supports reflink copies on macOS' APFS via the same syntax as GNU coreutils does on Linux.