LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Copying files from multiple folders into one (https://www.linuxquestions.org/questions/linux-general-1/copying-files-from-multiple-folders-into-one-398637/)

aardwolf64 01-02-2006 10:23 AM

Copying files from multiple folders into one
 
I've been using Linux as the primary OS on my web server for quite some time, and now use a Mac as my everyday computer at home. Generally I have been able to Google for anything I have needed, but the solution to this eludes me. Here's what I want to do:

Problem: I have many image files spread out in multiple folders from years of doing things, and I'd like to somehow get all of these into one folder without manually copying each one. I have been able to get a list of all of them using the find command. Is there a way to use the output from that and somehow feed it into the cp command, while still being able to choose an output folder?

I've tried using the pipe, but obviously cp needs more than one argument so it's not working for me.

bigrigdriver 01-02-2006 10:32 AM

If the filelist has one item per line, and if each line has the full path to the file name, you could try:

cp < filename.txt /path/to/new/folder

In this case, cp takes input from the txt file and copies to the new folder.

To move rather than copy, substitute mv for cp.

vls 01-02-2006 10:34 AM

Look at the '-ok' and '-exec' options to the find command.

aardwolf64 01-02-2006 11:52 PM

Thanks for all the fish...
 
bigrigdriver: For some reason that didn't work right. Oh well...

vls: Thanks for pointing me in the right direction. The exec option was exactly what I was looking for. In case you're interested:

$ find . -name "*.jpg" -ok cp {} /Images \;

aardwolf64 01-02-2006 11:53 PM

Hmmm... Ignore this second message. Safari gave me an error message, and I thought the first reply didn't post.


All times are GMT -5. The time now is 12:10 AM.