Does merging with the command cp -R overwrite old files?

Discussion in 'macOS' started by mrnabo, Oct 16, 2008.

  1. mrnabo macrumors newbie

    Joined:
    Aug 24, 2008
    #1
    Hi,

    Just wondering if using the Terminal command 'cp -R <new dir> <old dir>' actually replaces the contents of the folder entirely, or whether it just merges the content leaving older files and folders with the same name untouched?

    Let me know if I need to be clearer,

    Thanks
     
  2. fwhh macrumors regular

    Joined:
    Aug 11, 2004
    Location:
    Berlin, Germany
    #2
    This command will:
    copy all files from "<new dir>" into "<old dir>". If "<old dir>" contains a file with the same name as in "<new dir>", the file in "<old dir>" will be replaced with the one from "<new dir>". If you don't want this, use the "-n" switch, if you want to decide which file to keep, use the "-i" switch, eg.
    Code:
    cp -Ri <source dir> <target dir>
     
  3. mrnabo thread starter macrumors newbie

    Joined:
    Aug 24, 2008
    #3
    Thanks for clearing that up for me fwhh,

    So, i'm assuming that

    Code:
    cp -Rn <source dir> <target dir>
    Will leave same name files in the target directory?

    Is there a good place to learn about the Terminal, it's commands and uses? I'm interested in learning the next steps and getting my hands a bit more dirty with UNIX.

    Thanks
     
  4. mysterytramp macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #4
    There may be better ones, but here are two spots:

    here

    or here

    mt
     
  5. theiss macrumors newbie

    Joined:
    Oct 17, 2008
    #5
    The $15 book "Linux Phrasebook" by Scott Granneman really helped me out. Has plenty examples of commonly used commands.

    HTH,
    Troy
     
  6. fwhh macrumors regular

    Joined:
    Aug 11, 2004
    Location:
    Berlin, Germany
    #6
    Yes, it will.
    If you are unsure of a command, in most cases you can type eg.
    Code:
    man cp
    which will give you the manual page for "cp". In man pages you can search with the command
    Code:
    /<text to search>
    and repeat the search by pressing "n". Leave the man page by pressing "q".
     

Share This Page