non-existing parent directories - continued

Amit Dor-Shifer amitds at
Mon Nov 13 08:55:41 GMT 2006

I'm posting with reference to
(Couldn't find a way to post directly to thread).


    is there a way for rsync to create non-existing parent directories when
    syncing files to a destination? something similar to 'mkdir -p
    non-existing/directory'. i'm doing 'rsync -r /path/to/source
    /path/to/non-existing/directory', and the 'non-existing/directory'
    location doesn't exist.

Rsync will only create the top-level destination directory, not its
parents.  So just run an appropriate "mkdir -p" command before rsync.
If this needs to happen on the remote host of a transfer over SSH,
pass rsync something like --rsync-path="mkdir -p
/path/to/non-existing/directory && rsync".


Isn't the '-r' (--relative) option designed to do exactly that?
Here's my attempt to use a/m option. It created entire directory
structure at dest:

sh-3.1# ls /mnt/removable/root
ls: /mnt/removable/root: No such file or directory
sh-3.1# ls -R /root/temp/joe/
dfg  file1  file2

sh-3.1# ls -R /mnt/removable/root
ls: /mnt/removable/root: No such file or directory
sh-3.1# rsync -auvR /root/temp/joe /mnt/removable
building file list ... done

sent 4674504 bytes  received 88 bytes  9349184.00 bytes/sec
total size is 4673690  speedup is 1.00
sh-3.1# ls -R /mnt/removable/root


dfg  file1  file2



More information about the rsync mailing list