How to force rsync to create destination folder

CrazySquirrel picture CrazySquirrel · Feb 11, 2012 · Viewed 39.3k times · Source

Example:

rsync /tmp/fol1/fol2/fol3/foln user@addr:/tmp/fol1/fol2/fol3/foln

My main problem is folder /tmp/fol1 doesn't exist on remote machine.

Which arguments can I use to force rsync to create this tree?

Answer

Anand Chitipothu picture Anand Chitipothu · Oct 4, 2013

I ran into same issue today and found the solution here.

You can either do:

rsync -avR foo/bar/baz.c remote:/tmp/

or:

rsync -avR somedir/./foo/bar/baz.c remote:/tmp/

to create /tmp/foo/bar/baz.c in the remote machine.

see --relative/-R section of man rsync for more details.