LinuxQuestions.org
Visit Jeremy's Blog.
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: 113

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: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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: 113

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: 71
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: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
@Uncle_Theodore: Thanks for the correct explanation
 
Old 05-13-2009, 06:52 AM   #6
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,923
Blog Entries: 44

Rep: Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158
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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration