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/ picturewha tever1a.jp g
multimedia/archive2/00001/ picturewha tever2a.jp g
.
.
.
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...
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/
multimedia/archive2/00000/
.
.
.
multimedia/archive2/00001/
multimedia/archive2/00001/
.
.
.
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...
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/{} \;
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanx! Just what I had i mind! :)