Recursive Copy and SymLinks

Discussion in 'Mac Apps and Mac App Store' started by vtweb, Sep 13, 2004.

  1. vtweb macrumors newbie

    Joined:
    Sep 13, 2004
    #1
    Hello all. I've a fairly experienced PC user who has recently switched to a 15" Powerbook that I absolutely love! So far I'm settling in well, but there is one thing I'm having a problem with. I'm trying to figure out how to copy symbolic links without the copy following the link.

    The most obvious example is a recursive copy of the iPhoto directory. Albums appear to be just a collection of symbolic links. I'd like to write a shell script to copy my iPhoto files to an external firewire drive, but when I copy the iPhoto directory the symbolic links are followed resulting in lots of duplicate files (which when dealing with pictures takes up much more space then necessasry). Is there any type of command line switch that just copies the symbolic links? Ideally I would like to have an exact copy of the iPhoto directory (symlinks and all) in a new location. Does anybody know how to pull this off? Any help would be greatly appreciated! Thanks, Ron.
     
  2. jeremy.king macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #2
    in Terminal

    PHP:
    cp -rd /path/to/iPhoto/Library /path/to/copy/to
     
  3. vtweb thread starter macrumors newbie

    Joined:
    Sep 13, 2004
    #3
    Still Having Problems

    Thanks for the response, but when I try that command in a Terminal window I get illegal option -- d. Would switching shells matter? I'm using the default bash.
     
  4. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #4
    Check the man page for cp. There should be an option for copying symlinks instead of following them. I'm not at my Mac right now so I can't find the option for you.
     
  5. jeremy.king macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #5
    Why can't all the shells be the same :rolleyes: . thats a Redhat bash command.

    try

    cp -R -P -p /path/to/library /path/to/copy/to

    The default of cp -R is not supposed to follow symlinks, but the -P makes sure it doesn't. The -p will preseve all the ownership and permissions.

    Good luck.
     
  6. vtweb thread starter macrumors newbie

    Joined:
    Sep 13, 2004
    #6
    Thanks a Bunch!

    I just tried the above command and it worked. I never tried the -P option since the man pages say this is supposed to be the default behavior. That did the trick. Thanks a bunch!
     
  7. iMeowbot macrumors G3

    iMeowbot

    Joined:
    Aug 30, 2003
    #7
    The bash is pretty much the same. The confuzzlement comes from OS X using real BSD cp, and most Linux disributions using the GNU clone. GNU cp does support the BSD flags too, so using the flags found on OS X will make your fingers more portable.
     
  8. Westside guy macrumors 601

    Westside guy

    Joined:
    Oct 15, 2003
    Location:
    The soggy side of the Pacific NW
    #8
    I've noticed that Apple has been adding support for some flags over time as well. Moving to OS X 10.2.8 from Linux, the one I missed on a lot of commands was "show as human readable" (-h). It now is available for commands like df and ls, at least as of 10.3.5.
     
  9. vtweb thread starter macrumors newbie

    Joined:
    Sep 13, 2004
    #9
    Ah Ha!

    I just found the root of the problems. What the man pages don't tell you is that the "-r" option is supported as legacy, but that it has some quirks. One of which is that it doesn't handle symbolic links correctly. Using the "-P" switch will force it to handle symbolic links correctly, but as the man pages state "-P" is the default behavior when using "-R". As soon as I switched to the upper case R I no longer neede the "-P" switch.

    Again all thanks for all your help!
     
  10. mainstreetmark macrumors 68020

    mainstreetmark

    Joined:
    May 7, 2003
    Location:
    Saint Augustine, FL
    #10
    -r is legacy?

    Hmm, i guess so it'll get in line with chown and chmod and the like.

    Rats, I've been using -r for like 12 years, so I doubt I'll be changing.

    I wish OSX handled "ll" natively. (as a shortcut to "ls -l", which I've set up as an alias thing)
     
  11. vtweb thread starter macrumors newbie

    Joined:
    Sep 13, 2004
    #11
    Yea, looks like they're trying to get it matched up to the other commands. I've been using the -r for about 5 years now so I didn't even notice the Compatability section of the man pages. They say:

    COMPATIBILITY
    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 guess it pays to thoroughally read the man pages regardless of how familiar you think you are with the commands. :D Next time I'll know.
     

Share This Page