How can I copy a folder with scp that contains links? When I use the -r flag, all the data where the links point to are copied. How can I copy the link itself?

  • 1
    Since scp is for copying files across the network the concept of links doesn't really exist for it, especially since you're probably not copying the files to the exact same locations which would screw up absolute (from /) links. Could you expand on what you're trying to do and why?
    – Bytor
    Commented Nov 3, 2021 at 15:52

1 Answer 1


Use rsync. It gives you a lot more control over what gets copied. To copy directories recursively and copy symbolic links as such, use rsync -rl. But actually, most of the time, you should use rsync -a, which mostly makes an identical copy: directories are copied recursively, symbolic links and named pipes/sockets/devices are copied as such, permissions and time stamps are preserved, etc. (Access times are not preserved, however. And some “extra” attributes require extra flags.)

There are options to control how to copy symbolic links pointing outside the tree that's being copied: --safe-links skips them, --munge-links changes them into dangling links in a recoverable way. See the manual for details.

Rsync doesn't ship with ssh, but it's part of the default installation of many unix systems, and if not it's typically available as a packaged program. It does need to be installed on the server as well. It requires SSH access on the server, same as scp (if the access is to a restricted shell, it must allow rsync, which is often the case if it allows scp).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .