cp command

Discussion in 'MacBook Pro' started by Viti, May 7, 2011.

  1. Viti macrumors newbie

    Viti

    Joined:
    May 7, 2011
    Location:
    San Francisco
    #1
    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!
     
  2. Cantisama, May 7, 2011
    Last edited: May 7, 2011

    Cantisama macrumors member

    Joined:
    Feb 27, 2011
    #2
    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>)
     
  3. Viti thread starter macrumors newbie

    Viti

    Joined:
    May 7, 2011
    Location:
    San Francisco
    #3
    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.
     
  4. Cantisama macrumors member

    Joined:
    Feb 27, 2011
    #4
    Got this from wikipedia (http://en.wikipedia.org/wiki/Cp_(Unix)):

    That explains the difference in behavior of cp between Ubuntu and OSX.
     
  5. Viti thread starter macrumors newbie

    Viti

    Joined:
    May 7, 2011
    Location:
    San Francisco

Share This Page