I have visited several answers covering rsync and patterns, but couldn't find a solution to this particular problem. Assume that we've got a directory structure like the following on a remote machine, and we'd like to rsync that to a local directory. It's like mirroring only the "LATEST" part of a remote directory.

| |-LATEST -> version_3
| |-version_1
| |-version_2
| `-version_3
| |-LATEST -> version_1
|  `version_1
 |-LATEST -> version_3

LATEST is a symlink, and always points to the latest version on remote. I am currently trying to process rsync --list-only output with a shell script, and synchronize only LATEST versions. That's somewhat painful. It's a hunch; I believe that there is a way to do this with just some --include and --exclude patterns. Could someone help me writing a set of patterns that can do this?

Also, I'd prefer finding a way to remove an old version that's not LATEST anymore. My script goes through directories, and finds directories other than what LATEST symlinks to, and removes them. Is that possible with rsync?

1 Answer 1


I have learned that such a pattern matching isn't trivial. All directories within path from the root to LATEST must be enlisted among include patterns (either with --include=*/ --include=*/dir_1/ or --filter='+ /' --filter='+ /dir_1/'). Likewise, everything else must be excluded either with --exclude=* or --filter='- /unwanted_dir/*).

My script still parses --list-only output to find where LATEST is symlinked to. Afterwards, I include only paths that reach to LATEST.

I consider experimenting with rsync's command line arguments so that I can fetch LATEST as a symbolic link and wherever it points to.

You must log in to answer this question.

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