I have the following scenario where I need to copy directories which sometimes can be links and sometimes a directory with the same name. For instance, suppose this is the initial setup:

Source: /workspace/test/source/dir1 -> /tmp/test1

Destination: /workspace/test/dest/dir1 -> /tmp/test1

Now, suppose I remove the link in the source and create a folder with the same name, so now it looks like this:

Source: /workspace/test/source/dir1

Destination: /workspace/test/dest/dir1 -> /tmp/test1

What I'd like to do now, is to use rsync to copy the actual folder and "overwrite" the link, so it would look like:

Source: /workspace/test/source/dir1

Destination: /workspace/test/dest/dir1

Is there any way to do it via rsync? I know that if I use the rsync one level above, ie /workspace/test/source, it will work. Unfortunetly, I have to use the lowest level rsync.

Appreciate your response.

1 Answer 1


This is the default behaviour of rsync.


## Preamble
$ cd /tmp
$ mkdir src dst stuff
$ touch stuff/{a,b,c}
$ ( cd src && ln -s /tmp/stuff dir1 )
$ ( cd dst && ln -s /tmp/stuff dir1 )

## Symlinks are retained
$ cd /tmp
$ rsync -avv src/ dst/

## Change scenario
$ ls -l src
$ rm src/dir1 && cp -a /tmp/stuff src/dir1

## Symlinks are replaced according to the source
$ cd /tmp
$ rsync -avv src/ dst/
$ ls -l dst
  • Thanks for the comment. My intention is to rsync src/dir1 dst/dir1. I know that in top level it works, but the problem is I have to use the lowest level directory. Commented May 6, 2018 at 10:02
  • @Emil it can't work below the symlink because that's not part of the copy process Commented May 6, 2018 at 14:20

You must log in to answer this question.

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