1. 2
  1.  

    1. 3

      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.

    2. 3

      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.
      • … also when the destination argument happens to exist as a directory
      • … unless intended to be a directory – ends on /: Rsync behaves consistently in this case:
        • cp/rsync --recursive ~/Documents/ /mnt/backup/Documents/: Only Rsync does the same the first and the second time.
      • Add something like an --mkdir option, so you don’t need to repeat yourself if the destination is in a directory.