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.

At the moment I'm doing:

for i in mdx/[0-9][0-9].png; do cp $i ../../d_s_c/images/mdx ; done

But as well as the directory mdx, I also have other directories called ntt, etc.

How can I say 'For everything in a subdirectory, copy it across to the same subdirectory over at at ../../d_s_c/images'?

share|improve this question
    
Bonus points for 'copy if file has changed or does not exist in destination, leave otherwise'. –  Richard Sep 16 '11 at 17:31

1 Answer 1

up vote 1 down vote accepted

If you only want to copy things that have changed or are new, you'd be better off using rsync. To cover your other subdirectories, presuming you don't want everything.

MYLIST="mdx ntt etc"
for j in $MYLIST
do
        rsync -aq --include='[0-9][0-9].png' --exclude='*' ./$j/ ../../d_s_c/images/$j/ ; 
done

If you want to see what it's doing, you can substitute v for q in the parameters. I think this should work for you, you may have to make some adjustments for your environment.

share|improve this answer
    
This worked brilliantly, and I've learned something today, thank you! –  Richard Sep 16 '11 at 21:18

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.