Skip to main content
1 of 4

Is there a Linux copy program that preserves symlinks to directories and dereferences symlinks to files

I need to copy a directory tree full of symlinks to files on a different mount, but buried in the directory are 2 or 3 symlinks to directories outside of the copy tree. I need to copy the symlinks pointing to files as actual files but keep the 2 or 3 symlinks to directories as symlinks.

"scp -L" dereferences everything

I tried "rsync -avHS" followed by "rsync -avHS --keep-dirlinks" or "rsync -avHS -K" but those preserve both file and directory links on the destination so you end up with nothing dereferenced.