Roughly, I have a folder setup like this on a linux server:

/show/season01/show01/shows01e01.mkv
/show/season02/show01/shows02e01.mkv
/show/season03/show01/shows03e01.mkv

I want to eliminate the folders.... I want to copy the *.mkv files to the /show/ directory...

Can someone help me out with this one?

link|improve this question

80% accept rate
feedback

2 Answers

up vote 3 down vote accepted

Alex's answer is fine. Here's a couple of alternate ways to do it too:

  1. find + xargs:

    find /show -name "*.mkv" -print0 | xargs -0 -Imkv cp mkv /show/

  2. find + parallel:

    find /show -name "*.mkv" -print0 | parallel -0 -j+0 cp {} /show/

the only interesting thing about using parallel instead of find/exec is that it can execute multiple commands in parallel. The -j+0 arguments will make it launch as many jobs at once as there are cpu cores. That might not be particularly useful if this operation is completemy disk-bound, but potentially it could speed up copying large numbers of files.

link|improve this answer
Are you missing a closing quote or is the one that's there extraneous? – Dennis Williamson Feb 4 '11 at 5:19
feedback

find /show -name "*.mkv" -exec cp {} /show/ \; will do the trick

link|improve this answer
I cant edit because its a 1 letter change, but always put the trailing / on directories. So ... cp {} /show/ .... If /show doesnt exist, the files will all clobber eachother on copy rather than generating errors – Patrick Feb 4 '11 at 3:01
"-exec mv" has more sense. – poige Feb 4 '11 at 3:02
You are right guys. Edited a command to add a trailing slash. Yep, mv has more sense, but the task was to copy files for some reason. – Alex Feb 4 '11 at 3:05
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.