You are not logged in.

#1 2004-04-06 00:14:57

whol
Member
Registered: 2004-02-04
Posts: 155

how to cp a structure to a single directory?

I want to copy the contents of a large directory structure to a single directory.  I'm trying to use the "cp -r" command, but it copies the directory structure to the target directory. 

Is there a way to do this in a single command:

cp /pictures/wedding/wed01.jpg /mypictures/
cp /pictures/wedding/wed02.jpg /mypicutres/
cp /pictures/party/party01.jpg /mypictures/
cp /pictures/morning/morning01.jpg /mypictures/

I actually want to copy *all* the jpg files in each different subdirectory to a single target directory.

Any suggestions?

thx!

Offline

#2 2004-04-06 01:55:18

Win
Member
Registered: 2004-03-04
Posts: 155

Re: how to cp a structure to a single directory?

Hi whol.

Use the 'find' command with backticks to create a list:

cp `find /source-dir -name "pattern"` /target-dir

For example, to copy all the .jpg files under the pictures directory to the mypictures directory:

cp `find /pictures -name "*.jpg"` /mypictures

Regards,

Win

Offline

#3 2004-04-06 03:00:24

whol
Member
Registered: 2004-02-04
Posts: 155

Re: how to cp a structure to a single directory?

thanks win,

maccroni gave me another way on IRC:

(from inside the dir i want to copy)

find . -type f -exec cp {} /target/directory ;

thx!

Offline

Board footer

Powered by FluxBB