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?

2 Answers 2

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.

1
  • Are you missing a closing quote or is the one that's there extraneous? Feb 4, 2011 at 5:19
3

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

3
  • 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 4, 2011 at 3:01
  • "-exec mv" has more sense.
    – poige
    Feb 4, 2011 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, 2011 at 3:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .