1

I want to use the default cp on my mac to copy a folder to another destination. I want it to overwrite the target. But if the target folder exists, cp copies the source into the target instead of overwriting it.

In GNU cp, there is --no-target-directory. The argument does not exist on Mac's cp.

I would prefer not to switch to GNU's cp because I do not know if it's as fast as Mac's builtin cp (or maybe it is? I have not tested it). Performance is important here.

I also would prefer not to switch because that just seems like an overkill solution. Mac's cp work for me. There's a guarantee that it's installed on every mac.

terdon
  • 242,166
  • 1
    Does your man page for the MacOS cp command describe the -R option and appending the source folder name with /? Have you tried the -R and/or -a options? (My MacOS Monterey has these, but I don't know if earlier versions do also) – Sotto Voce Jul 31 '22 at 12:42
  • 2
    For what it's worth, I doubt any cp implementation will have significant differences in speed. They have different options and choices on how to handle edge cases, but the speed of the different cp implementations is very unlikely to differ. – terdon Jul 31 '22 at 14:09
  • @SottoVoce I think your solution works perfectly, just like https://unix.stackexchange.com/a/228637/175318 says. Thanks! – Matt Groth Jul 31 '22 at 21:20

0 Answers0