LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   cp command question . (https://www.linuxquestions.org/questions/linux-newbie-8/cp-command-question-71317/)

jesse_mair 07-09-2003 12:34 PM

cp command question .
 
I have a bunch of mp3's in tons of folders on cd's . I want to copy each mp3 from all the folders using a comand line to a folder on the hard drive . ( i.e. only the files , not the folders )

@: cp *.mp3 mymp3folder

but this will only copy the mp3's in the root directory of the cd drive , not everything inside all the folders .

any help would be great , or even a direction on where to look .
thank you kindly =)

acid_kewpie 07-09-2003 12:45 PM

just the files? i.e. all lump them in one single directory...? try this from the base directory
Code:

for i in `find . -iname *mp3`
do
  cp $i /destination/`basname $i`
done


jpbarto 07-09-2003 12:54 PM

Ahh Daniel-san. You must write Bash script. Let me get this straight ... you want to recursively copy mp3 files from subdirectory upon subdirectory and dump all those files into ONE directory on another disk correct?

(linux guru's tell me if I do wrong)
I think the quickest way would be to write some bash script that can be executed from the command line...

something like this:

foreach file in `ls -R`; then
if [ -d $file ]; then
cp $file/*.mp3 mymp3dir
fi
hcaerof

(that is probably a horribly wrong doesn't-even-look-like-bash bash script. I haven't had to write script for some time. However it is possible. Essentially you need to retrieve a listing of all subdirectories and then for each subdirectory execute your copy command. pretty simple in theory... just a matter of finding the right commands.

jesse_mair 07-09-2003 12:55 PM

thanks guys .. i'll give that a go ,,...


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