I believe cp on Linux uses copy_file_range, not read and write. In addition to bypassing copies to and from userspace, this means that copy-on-write filesystems can avoid copying the data and can instead just add a new reference.
In good tradition, cp is also an example of a command with a surprising arsenal of footguns. Idempotency was apparently not its design goal.
cp
If it wasn’t for the goal of compatibility, I would be tempted to make some adjustments (I think someone needs to do this):
--no-clobber
/
cp/rsync --recursive ~/Documents/ /mnt/backup/Documents/
--mkdir
I believe cp on Linux uses copy_file_range, not read and write. In addition to bypassing copies to and from userspace, this means that copy-on-write filesystems can avoid copying the data and can instead just add a new reference.
In good tradition,
cp
is also an example of a command with a surprising arsenal of footguns. Idempotency was apparently not its design goal.If it wasn’t for the goal of compatibility, I would be tempted to make some adjustments (I think someone needs to do this):
--no-clobber
should probably have been the default. Or succeed if they are already duplicates./
: Rsync behaves consistently in this case:cp/rsync --recursive ~/Documents/ /mnt/backup/Documents/
: Only Rsync does the same the first and the second time.--mkdir
option, so you don’t need to repeat yourself if the destination is in a directory.