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

vtweb

macrumors newbie
Original poster
Sep 13, 2004
5
0
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.
 
Still Having Problems

kingjr3 said:
in Terminal

PHP:
cp -rd /path/to/iPhoto/Library /path/to/copy/to

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.
 
vtweb said:
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.
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.
 
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.
 
Thanks a Bunch!

kingjr3 said:
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.

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!
 
kingjr3 said:
Why can't all the shells be the same :rolleyes: . thats a Redhat bash command.
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.
 
iMeowbot said:
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.

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.
 
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!
 
-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)
 
mainstreetmark said:
-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)

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.