Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have the following loop in zsh:

 for x in my_folders*; 
 do 
   rsync -adrv $x/foo/bar/ /foo2/bar2/new_dir/$x/
 done

new_dir does not exist before calling rsync, and I would like rsync to create it, along with everything else needed for the copy operation.

I am passing rsync the flags d and r but it complains with:

rsync: mkdir "/foo2/bar2/new_dir/item1" failed: No such file or directory (2)

It apparently assumes that the folders /foo2/bar2/new_dir/$x/ exist prior to the copying, which don't. With this:

  • Is there a way to ask rsync to create any necessary directories needed for the copy operation to work?
share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

Looking at the rsync man page I don't see an option for your scenario. But what about adding the directory manually before starting the sync, thus avoiding your issue?

for x in my_folders*; 
do  
   mkdir -p /foo2/bar2/new_dir/$x
   rsync -adrv $x/foo/bar/ /foo2/bar2/new_dir/$x/
done
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.