I'm trying to copy a bunch of files/directories using a terminal command, cp. The command I'm using is:

sudo cp -r *.tests ~/Desktop

tests are directories with stuff in them. However I get a few No such file or directory errors. I'm not sure how I can get this error if I'm doing a recursive copy. If it doesn't exist, how would I be seeing it?

migrated from stackoverflow.com Aug 19 '11 at 21:22

This question came from our site for professional and enthusiast programmers.

  • Which version of Unix? Do any of the filenames have spaces in them? ( I guess that shouldn't matter, but ... ?). Good luck. – shellter Aug 19 '11 at 19:28
  • Mac OS X, some do, some don't – JPC Aug 19 '11 at 19:31

If the directory you are in, or any below it, are being modified while you are doing the copy you would see that error. For example, if after you started the cp some other process deleted a file or directory.

  • I know that no other process is touching those files – JPC Aug 19 '11 at 19:18
  • Unless your drive is going bad or something similar, I'd say it's most definitely something other process deleting those files. lsof is your friend. – Kaleb Pederson Aug 19 '11 at 19:20
  • After running cp and seeing the files/directories that apparently don't exist, I run lsof and those files/directories are not in the list output by lsof – JPC Aug 19 '11 at 19:36
  • Is it how cp is traversing your directories? Some symlink sending you off into the weeds? Hard to debug this type of problem without seeing the filesystem. :-/ – AlG Aug 19 '11 at 19:56

From the cp man page (under OS X v10.6.8):

Historic versions of the cp utility had a -r option.  This implementation
supports that option; however, its use is strongly discouraged, as it
does not correctly copy special files, symbolic links, or fifo's.

So try cp -R instead. If that doesn't do it, is there anything notable about the files it gets errors on? Do they exist? Are they AppleDouble files (metadata pseudo-files with names starting with "._")?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.