Shell script to cycle through a directory with subdirectories of images and copy some images to diff directory based on filename

I have a directory "multimedia/archive" with many subdirectories named like this: "00000", "00001", ... ,"01075".
The subdirectories contains different versions of many pictures. The directory "00000" might have a file "picture1a.jpg", "picture1b.jpg", "picture1c.jpg" and so on. As well as "picture2a.jpg", "picture2b.jpg", "picture2c.jpg" and so on.

I would like to keep my original multimedia/archive as it is, but make a copy of all my *a.jpg files to another main directory (e.g multimedia/archive2) with the same subdirectory structure...

Hence I want my files like this:

How do I do this with a shell script?

I have seen this article:, but I'm not able to make the correct adjustment...

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nick UpsonPrincipal Operations EngineerCommented:
cp -r multimedia/archive multimedia/archive2 is the easy one if they already only contain those you wish to copy

How about :

create the  directory structure you need in the desitantion :
find /multimedia/archive/ -type d -exec mkdir -p /multimedia/archive2/{} \;  

Then copy the files over :
find /multimedia/archive/ -type f -name "*a.jpg" -exec cp -p {} /multimedia/archive2/{} \;

cd multimedia
find . -name "picture*a.jpg | while read file
   dir=`dirname $file`
   if [ -d archive2/$dir ]
         mkdir -p archive2/$dir
   cp $file archive2/$dir

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kvaadeAuthor Commented:
Thanx! Just what I had i mind!  :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.