0

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?

Mark Henderson
  • 68,823
  • 31
  • 180
  • 259
LVLAaron
  • 436
  • 6
  • 13

2 Answers2

3

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

Alex
  • 7,939
  • 6
  • 38
  • 52
  • 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 – phemmer Feb 04 '11 at 03:01
  • "-exec mv" has more sense. – poige Feb 04 '11 at 03: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 04 '11 at 03:05
3

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.

Phil Hollenback
  • 14,947
  • 4
  • 35
  • 52