Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 697
  • Last Modified:

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: http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Q_22894420.html, but I'm not able to make the correct adjustment...

0
kvaade
Asked:
kvaade
1 Solution
 
NickUpsonSenior Network EngineerCommented:
cp -r multimedia/archive multimedia/archive2 is the easy one if they already only contain those you wish to copy

0
 
edster9999Commented:
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/{} \;
0
 
omarfaridCommented:
try

cd multimedia
find . -name "picture*a.jpg | while read file
do
   dir=`dirname $file`
   if [ -d archive2/$dir ]
   then
         ;
   else
         mkdir -p archive2/$dir
   fi
   cp $file archive2/$dir
done
0
 
kvaadeAuthor Commented:
Thanx! Just what I had i mind!  :)
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now