Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I need some help in this issue:

I want sync /path/first/ with /path/second/, /path/third/ ..etc

so I've tried this:

rsync -rv /path/first/ /path/{second,third,fourth}/

But it worked only for last directory. What's wrong? Thanks.

share|improve this question

migrated from stackoverflow.com Jan 11 '13 at 20:50

This question came from our site for professional and enthusiast programmers.

1  
Those braces are NOT interpreted by rsync but by the shell. –  fge Jan 11 '13 at 20:04

2 Answers 2

rsync only takes one target. Use a for loop instead.

for dest in {second,third,fourth}
do
  rsync -rv /path/first/ /path/"$dest"/
done
share|improve this answer
    
Got it, thanks. –  Sloan Jan 11 '13 at 21:40

How about it?

for qw in `ls -d /path/*`; do  rsync -rv /path/first /path/$qw; done
share|improve this answer
1  
I count 3 bugs. 4, if you want to be picky. –  Ignacio Vazquez-Abrams Jan 11 '13 at 20:13
    
what do you mean? –  Satish Jan 11 '13 at 20:18
    
First you should never attempt to loop ls output with for. Your script breaks if any of the folders contains a space in their path. Also you need to quote the variable for similar reasons. Pipe find … -print0 through while IFS= read -r -d '' file; do … "$file"; done, or so to be safe. –  slhck Jan 11 '13 at 21:40

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.