<p>What is the simplest way of copying symbolic links on the Mac?</p>

<p>A python or perl solution would be preferred, but any solution would be a help.</p>

<p>I am copying frameworks for an installation package, and need the links to be maintained</p>

In python you can use
os.readlink
and
os.symlink
to perform this action. You should check if what you operate on is actually a symbolic link with
os.lstat
and
stat.S_ISLNK
```
```
import os, stat
if stat.S_ISLNK(os.lstat('foo').st_mode):
    src = os.readlink('source')
    os.symlink(src, 'destination')
```
```
You could do it with the
-R option of cp
. This works because cp by default does not follow symbolic links but barks at copying non-files without specifying -R which means recursion.
```
```
cp -R source destination
```
```
In python that would be with the
subprocess.call
```
```
from subprocess import call
call(['cp', '-R', 'source', 'destination'])
```
```
Note that a
macosx alias
is not a symbolic link and therefore symbolic link specific treatment will fail on it.