I have a directory that contains symbolic links to other directories located on different media on my system:

/opt/lun1/2011
/opt/lun1/2010
/opt/lun2/2009
/opt/lun2/2008
/opt/lun3/2007

But the symbolic links show up as:

/files/2011
/files/2010
/files/2009
/files/2008
/files/2007

How can I perform an rsync that follows the symbolic links?

e.g.:

rsync -XXX /files/ user@server:/files/

up vote 84 down vote accepted

The -L flag to rsync will sync the contents of files or directories linked to, rather than the symbolic link.

  • When I do this, all the receiver symbolic links get deleted and my sender starts re-sending the files. – ensnare Mar 10 '11 at 16:40
  • Isn't that what you want? I thought you wanted to have the real files on the receiving side, not just the symlinks. Do you mean you want the symlinks copied as symlinks, but automagically rewritten to point to the "right" place on the receiving system? If so, that's not what is normally meant by "an rsync that follows the symbolic links". – MadHatter Mar 10 '11 at 17:10
  • 3
    Hi -- these are directories. I got this to work with the -K flag. – ensnare Mar 10 '11 at 21:20
  • 3
    I'm sure SO is making me more stupid.. – John Hunt Nov 7 '14 at 11:53
  • 2
    To clarify, -LK if you want to follow both symlinked files and directories – Mahn Jul 14 '16 at 21:14

Just ran into this problem. And if you want rsync to treat symlinked directories as directories, you want the K option

rsync -K /files/ user@server:/files/

  • You might also want to add the --copy-unsafe-links option – Gregory Magarshak Aug 2 '16 at 16:25

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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