TIL: File clone over full copy (depends on your fi...
# dev
b
TIL: File clone over full copy (depends on your filesystem). MacOS's APFS supports fileclone using
cp -c
. In case copy-on-write is required, not like symbolic link where modification will effect the source, data is kept and new one will be created if we try to update. Example of how to use and the time of copy/clone: create large file
Copy code
$ dd bs=1024 count=10485760 </dev/urandom > data
copy the file
Copy code
time cp data data-cp
cp data data-cp  0.01s user 4.17s system 79% cpu 5.269 total
clone the file
Copy code
time cp -c data data-clone
cp -c data data-clone  0.00s user 0.00s system 70% cpu 0.004 total
👍 1
👏 1
🤯 2
a
Cool! I think on Linux systems you can
cp --reflink=auto
(which has the advantage of not failing if the FS doesn't support it) or
--reflink=always
to fail fast.
🙌 1
b