Link to home
Start Free TrialLog in
Avatar of kvaade
kvaade

asked on

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:
multimedia/archive2/00000/picture1a.jpg
multimedia/archive2/00000/picture2a.jpg
.
.
.
multimedia/archive2/00001/picturewhatever1a.jpg
multimedia/archive2/00001/picturewhatever2a.jpg
.
.
.

How do I do this with a shell script?

I have seen this article: https://www.experts-exchange.com/questions/22894420/Need-a-shell-script-to-cycle-through-a-directory-of-images-and-copy-images-to-diff-directory-based-on-filename.html, but I'm not able to make the correct adjustment...

Avatar of Nick Upson
Nick Upson
Flag of United Kingdom of Great Britain and Northern Ireland image

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/{} \;
ASKER CERTIFIED SOLUTION
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kvaade
kvaade

ASKER

Thanx! Just what I had i mind!  :)