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'?

link|improve this question

50% accept rate
Bonus points for 'copy if file has changed or does not exist in destination, leave otherwise'. – Richard Sep 16 '11 at 17:31
feedback

1 Answer

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.

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

Your Answer

 
or
required, but never shown

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