LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 05-12-2009, 08:15 AM   #1
deostroll
Member
 
Registered: Aug 2007
Location: Bangalore
Distribution: fedora
Posts: 112

Rep: Reputation: 15
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...
 
Old 05-12-2009, 08:19 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

You can use find's -exec option:

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

Hope this helps.

Last edited by druuna; 05-12-2009 at 08:20 AM.
 
Old 05-13-2009, 06:38 AM   #3
deostroll
Member
 
Registered: Aug 2007
Location: Bangalore
Distribution: fedora
Posts: 112

Original Poster
Rep: Reputation: 15
I don't understand the part that starts from '-exec' onwards...! What are we trying to communicate?
 
Old 05-13-2009, 06:42 AM   #4
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 60
Quote:
Originally Posted by deostroll View Post
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.
 
Old 05-13-2009, 06:49 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
@Uncle_Theodore: Thanks for the correct explanation
 
Old 05-13-2009, 06:52 AM   #6
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 11,289
Blog Entries: 3

Rep: Reputation: 1446Reputation: 1446Reputation: 1446Reputation: 1446Reputation: 1446Reputation: 1446Reputation: 1446Reputation: 1446Reputation: 1446Reputation: 1446
Hi,

Quote:
Originally Posted by deostroll View Post
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!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy folder/files according to modification date bkcreddy17 Programming 14 10-15-2008 07:24 PM
How to copy files from diffrent folders to a single folder cadcrazy Linux - Software 3 09-18-2008 09:57 AM
Copy single file to multiple locations - What am I doing wrong decartes Linux - Newbie 7 04-26-2008 04:09 PM
To copy files from a CD to a folder on your system Gins Linux - General 20 10-30-2006 12:53 PM
Create script in CentOS4 to copy folder but promt user to enter name of destination mastermindpr Linux - General 2 02-08-2006 10:45 AM


All times are GMT -5. The time now is 06:56 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration