Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

Your Answer


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.