Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Viti

macrumors newbie
Original poster
May 7, 2011
3
0
San Francisco
Hi everyone!

I recently bought a MacBook Pro and it's my first Mac system, so I'm still getting used to it. I come from an Ubuntu machine, and I hoped that all the terminal commands would work more or less the same way, but I have some problems with the cp command.

In fact, when I try to use the cp command to copy a folder, if the folder ends with / it just doesn't work, but I don't get an error neither.

For example, if I try:

cp -r Hello/ Documents/

It doesn't work. But if I try:

cp -r Hello Documents/

The it works! Any idea why is this happening? For me is much more convenient the first way, cause with the tab button you always autocomplete the folders ending with /.

Thanks for your help in advance! Bye!
 
Not sure why you posted this in the MacBook Pro section, this isn't a laptop specific question.

-Edit- The following info only applies to nonempty folders, see post #4 for generic info. -End Edit- Anyway, cp -r folder1/ folder2/ works just fine in OSX. It doesn't matter if you include the / at the end of the source folder path, but it does seem to make a difference for the destination folder path. You can either:
1) include / at the end of the destination folder path, then folder1 will be copied to folder2 (creating folder2/folder1/<contents of folder1>)
2) don't include / at the end of the destination folder path, then the contents of folder1 will be copied to the root of folder2 (folder2/<contents of folder1>)
 
Last edited:
I post it here because I don't know where to post it.

Anyway, this is what is happening to me. Here I copy an example taken directly from my terminal.

Victor-Munozs-MacBook-Pro:hola Viti$ mkdir probe
Victor-Munozs-MacBook-Pro:hola Viti$ mkdir copy
Victor-Munozs-MacBook-Pro:hola Viti$ cp -r copy/ probe/
Victor-Munozs-MacBook-Pro:hola Viti$ ls probe/
Victor-Munozs-MacBook-Pro:hola Viti$ cp -r copy probe/
Victor-Munozs-MacBook-Pro:hola Viti$ ls probe/
copy

Thanks for your help.
 
Got this from wikipedia (http://en.wikipedia.org/wiki/Cp_(Unix)):

To copy a directory, including all its files and subdirectories, to another directory, enter:

cp -R /home/nick/clients /home/nick/customers

This copies the clients directory, including all its files, subdirectories, and the files in those subdirectories, to the customers/clients directory. Be careful about including a trailing slash in the source directory, however. If you run cp -R /home/nick/clients/ /home/nick/customers on a GNU-based system, it does the same thing as without the slash; however, if you run the same thing on a BSD-based system, it will copy all the contents of the "clients" directory over, instead of the "clients" directory itself.

That explains the difference in behavior of cp between Ubuntu and OSX.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.