LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Copy files from various locations to a single destination folder (http://www.linuxquestions.org/questions/linux-newbie-8/copy-files-from-various-locations-to-a-single-destination-folder-725421/)

deostroll 05-12-2009 08:15 AM

Copy files from various locations to a single destination folder
 
I am able to search recursively and list mp3 files. I use the following command for it:
find -iname '*.mp3'

I want to use this as input for a copy command (cp). Any ideas?

PS: not at a linux os at the moment. Hence not sure if this post should work...

druuna 05-12-2009 08:19 AM

Hi,

You can use find's -exec option:

find . -type f -iname '*.mp3' -exec cp {} /a/specific/dir/ \;

Hope this helps.

deostroll 05-13-2009 06:38 AM

I don't understand the part that starts from '-exec' onwards...! What are we trying to communicate?

Uncle_Theodore 05-13-2009 06:42 AM

Quote:

Originally Posted by deostroll (Post 3539280)
I don't understand the part that starts from '-exec' onwards...! What are we trying to communicate?

cp is the command to execute. The two braces, {}, stand for "what to copy", and the directory at the end -- where to copy.
This symbol, {} is the standard way for the find command to represent the file that has been found.

druuna 05-13-2009 06:49 AM

@Uncle_Theodore: Thanks for the correct explanation :)

onebuck 05-13-2009 06:52 AM

Hi,

Quote:

Originally Posted by deostroll (Post 3539280)
I don't understand the part that starts from '-exec' onwards...! What are we trying to communicate?

You can always 'man command';

Quote:

excerpt from 'man find;

-exec command ;
Execute command; true if 0 status is returned. All following arguments to find are taken to be arguments to the command until an argument consisting of `;' is encountered. The string `{}' is replaced by the current file name being processed everywhere it occurs in the arguments to the command, not just in arguments where it is alone, as in some versions of find. Both of these constructions might need to be escaped (with a `\') or quoted to protect them from expansion by the shell. The command is executed in the starting directory.
Look at 'Linux Command Guide' and 'Linux Shell Scripting Tutorial v1.05r3'.

These links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!


All times are GMT -5. The time now is 07:46 PM.