LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Find files and copy the results to desired folder? (https://www.linuxquestions.org/questions/linux-newbie-8/find-files-and-copy-the-results-to-desired-folder-678693/)

colbert 10-23-2008 09:12 PM

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 :)

i92guboj 10-23-2008 09:33 PM

Code:

find /path/to -iname 'whatever' -exec cp '{}' /path/to/destination/ \;

colbert 10-23-2008 09:36 PM

Thanks i92guboj, but I got this:

Code:

/media/seagate/guitar/tabstolearn > find -iname "*acoustic*" -exec cp '{}' test/
find: missing argument to `-exec'

:(

i92guboj 10-23-2008 10:08 PM

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.

colbert 10-23-2008 11:04 PM

Thanks so much! It works now :) :D

colbert 11-08-2008 01:00 PM

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 :)

i92guboj 11-08-2008 11:21 PM

You want to look into functions, and not aliases.


All times are GMT -5. The time now is 03:02 PM.