Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy nested folders contents to one folder recursively (terminal)

Tags:

I have a Wordpress upload folder that is structured using subfolders for months.

wolfr2:uploads wolfr$ tree . . |-- 2007 |   |-- 08 |   |   |-- beautifulkatamari.jpg |   |   |-- beautifulkatamari.thumbnail.jpg |   |   |-- beetle.jpg |   |   |-- beetle.thumbnail.jpg 

How do I use terminal to copy all the images recursively into another folder? I can't seem to wildcard folders like you can wildcard filenames. (e.g. *.jpg or *) (I'm on Mac OSX)

cp -R ./*.jpg . 

?

like image 822
Wolfr Avatar asked Dec 20 '09 15:12

Wolfr


1 Answers

This will copy all *.jpg files from the current folder to a new folder and preserve the directory structure.

tar cvfp `find . -name "*.jpg"` | (cd <newfolder>; tar xfp -) 

To copy without preserving the directory structure:

cp `find . -name "*.jpg"` <newfolder> 
like image 93
Richard Pennington Avatar answered Sep 29 '22 03:09

Richard Pennington