Take the 2-minute tour ×

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
add comment

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
        rsync -aq --include='[0-9][0-9].png' --exclude='*' ./$j/ ../../d_s_c/images/$j/ ; 

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
add comment

Your Answer


