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 10-23-2008, 10:12 PM   #1
colbert
LQ Newbie
 
Registered: Jul 2008
Posts: 19

Rep: Reputation: 0
Question Find files and copy the results to desired folder?


I'm trying to find files in a folder, say ones matching "acoustic" and then move all the results found into another folder.

I have done this to find the files:

Code:
/media/seagate/guitar/tabstolearn > find -iname "*acoustic*"
./Hendrix, Jimi/Hendrix, Jimi - Hear My Train A Comin' (acoustic).gp3
./Radiohead/Radiohead - Fake Plastic Trees (Acoustic Version ).gp3
./Radiohead/Radiohead - Creep Acoustic.gp4
./Radiohead/Radiohead - Lucky Acoustic.gp4
./Radiohead/Radiohead - Just Acoustic.gp3
./Radiohead/Radiohead - creep ( version acoustic ) _-).gp3
./Metallica/Metallica - Nothing Else Matters - Acoustic Remix.gp3
./Metallica/Metallica - Nothing Else Matters (arranged for one acoustic guitar).gp3
./Beatles/Beatles (The) - Yesterday (acoustic single guitar).gp3
./Lynyrd Skynyrd/Lynyrd Skynyrd - Sweet Home Alabama (Acoustic Version).gp3
./Lynyrd Skynyrd/Lynyrd Skynyrd - Free Bird (Acoustic).gp4
./Rolling Stones - Paint It Black (Acoustic Arrangement).gp5
./layla_acoustic_ver5.gp3
./Blues Acoustic Guitar
./Blues Acoustic Guitar/Blues Acoustic Guitar - Blues Correction, Blues Chords.gp3
./Blues Acoustic Guitar/Blues Acoustic Guitar - Blues Acoustic Guitar Lesson 1.gp3
./Led Zeppelin/Led Zeppelin - Hey Hey What Can I Do (Acoustic).gp3
./Beatles (The) - Yesterday (acoustic single guitar).gp3
./Guns N' Roses/Guns N' Roses - November Rain (Acoustic Version).gp3
How can I move these files (the results only that match my "find" search of course), into a specific folder now??

I have tried adding:

Code:
find -iname "*acoustic*" | cp *
But that just copied all the files, didn't pertain to only the results of the find search.

Thanks for any help
 
Old 10-23-2008, 10:33 PM   #2
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Code:
find /path/to -iname 'whatever' -exec cp '{}' /path/to/destination/ \;

Last edited by i92guboj; 10-23-2008 at 11:08 PM.
 
Old 10-23-2008, 10:36 PM   #3
colbert
LQ Newbie
 
Registered: Jul 2008
Posts: 19

Original Poster
Rep: Reputation: 0
Thanks i92guboj, but I got this:

Code:
/media/seagate/guitar/tabstolearn > find -iname "*acoustic*" -exec cp '{}' test/
find: missing argument to `-exec'
 
Old 10-23-2008, 11:08 PM   #4
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Ops, I missed the punctuation at the end of the command. Add "\;" to the end (without the quotes).

I also fixed the post above to avoid further confusion.
 
Old 10-24-2008, 12:04 AM   #5
colbert
LQ Newbie
 
Registered: Jul 2008
Posts: 19

Original Poster
Rep: Reputation: 0
Thanks so much! It works now
 
Old 11-08-2008, 02:00 PM   #6
colbert
LQ Newbie
 
Registered: Jul 2008
Posts: 19

Original Poster
Rep: Reputation: 0
Hey i'm trying to add this to my .bashrc so I can make an alias, with the idea of something like

Code:
findcp string /desired/path
To make it quick and easy to use. I have tried this so far but it does not work (alias in .bashrc first then test run):

Code:
alias findcp='find -iname "*$1*" -exec cp '{}' $2/ \;
Code:
~/Desktop/new gdm > ls
test  woobuntuv2.tar.gz  wooden.tar.gz
~/Desktop/new gdm > findcp woobun test/
cp: omitting directory `.'
cp: omitting directory `./test'
cp: cannot create regular file `/woobuntuv2.tar.gz': Permission denied
cp: cannot create regular file `/wooden.tar.gz': Permission denied
~/Desktop/new gdm >
Would really appreciate any help with getting a functional alias, thanks a ton
 
Old 11-09-2008, 12:21 AM   #7
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
You want to look into functions, and not aliases.
 
  


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 08:24 PM
How to copy files from diffrent folders to a single folder cadcrazy Linux - Software 3 09-18-2008 10:57 AM
To copy files from a CD to a folder on your system Gins Linux - General 20 10-30-2006 01:53 PM
How to copy in a script files to a samba folder? Julianus Linux - Networking 1 10-09-2004 08:29 PM
php - find files (photo*.jpg) and return results to an array omarswan Programming 2 06-20-2003 12:42 PM


All times are GMT -5. The time now is 06:39 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration