Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to sync a big folder hierarchy between two machines. I want to copy the contents of the symlinks if they are absolute, for eg it points to /some/folder/someFile I want to retain the symlinks if they are relative, for eg, it points to ../../somefolder How do I do this?

Edit: Basically I try to avoid recursion. I tried --copy-unsafe-links option, it copies absolute links but skips internal or relative links, does not retain the link.

share|improve this question
up vote 3 down vote accepted

I think you should be able to use the --copy-unsafe-links option on rsync to copy file data where the symlink points outside of the synchronized folder space but sends just the symlink when the file pointed to is also being synced. This is in addition to --links (-l, it's included in -a) to copy relative symlinks inside the copied hierarchy as symlinks.

If that isn't fine tuned enough, you will probably have to create a list of links you do and don't want to send using find and pass those as input to rsync in the form of include/exclude lists.

share|improve this answer
it temporarily worked for my problem. Basically I try to avoid recursion but some files have absolute symlink to the synchronized folder. This causes recursion still. :(. It would have been great if there was some option to select symlinks based on pattern just like we are able to select files based on --exclude – balki Jun 17 '11 at 15:43
Sounds like you should consider asking the rsync developers directly. – Thorbjørn Ravn Andersen Jun 17 '11 at 15:45
Sorry, this didn't work, it copies external links but skips links which point to synchronized folder(relative links). It does not copy/create the symlink. – balki Jun 17 '11 at 15:54
Did you combine this with --links to preserve symlinks? It should work but you have to use both arguments. If that's not enough control, you'll have to make your lists of includes and excludes to pass to rsync manually. – Caleb Jun 17 '11 at 16:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.