Another feature proposal and implementation plan: --strip-prefix

Wayne Davison wayned at
Wed Apr 14 23:53:35 GMT 2004

On Wed, Apr 14, 2004 at 07:36:23PM -0400, Edwin Olson wrote:
> Suppose you're copying a source file /a/b/c/d/e/f/g/h/myfile and you 
> want it stored on some other filesystem /backup, but you want the source 
> path to be truncated so that the file actually ends up as: /backup/h/myfile.

(I'm assuming that you're using the --relative option, or you wouldn't
be having this issue.)

If you're pushing dirs, do a chdir before calling rsync and then copy a
relative path:

cd /a/b/c/d/e/f/g
rsync -avR h/myfile remote:/backup

If you're pushing OR pulling, you can accomplish the same thing using

echo h/myfile | rsync -av --files-from=- remote:/a/b/c/d/e/f/g /backup

With --files-from, the source path specifies the default dir, and the
--relative option is on by default, so you'd end up with your desired


More information about the rsync mailing list