I am seeing some unexpected results while copying package files in a shell script. There are two interrelated issues.

  1. I have commands similar to the following in a shell script:

    cp -rp path/to/package/file destination/directory

The problem that I am seeing is that sometimes the package is copied as a whole, which is what I want. Other times the package "goes away" and just the contents of the package ends up in the destination/directory. I don't see the pattern which is causing this to happen differently. Specifically, in the shell script, the package is copied as a whole. But when I try the exact command from the terminal, I get only the contents.

  1. In the shell script, while the package seems to be copied as a whole, it takes a very long time. Like 20 minutes to copy a 17MB file to a USB drive. When I copy the same package via Finder, it copies in about a minute. Then during testing when I rerun the script, it does not take 20 minutes, but just the minute.

These two results are unexpected. I would expect the same result each time, not varying results with the package verses package contents, and the time to run the script.

Any ideas?

1 Answer 1


I'm not sure about #2, but I suspect #1 is due to trailing slashes in the file path. cp -Rp /path/to/Application.app /path/to/destination will copy the entire package, while cp -Rp /path/to/Application.app/ /path/to/destination (note the trailing slash after the source) will copy just the contents.

BTW, you should use cp -R instead of cp -r -- in some implementations of cp they're the same, but in some versions the lowercase option has ... oddities. According to the man page on OS X:


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.

  • I thought I had tried both with and without the trailing slash. But it appears that you are correct about the trailing slash. And that probably explains the "sometimes it does and sometimes it doesn't, as the scripts vary. I am considering this question answered. Aug 30, 2013 at 16:04
  • Re the -R vs -r, I did just notice this on the man page, and while -r works on OS X, have started changing over my usage. Aug 30, 2013 at 16:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .