# Shell script to recursively move files



## th0r0din50n (Jun 3, 2013)

Ok, so I've seen posts like this, but not quite to the point that I need. I've got a directory set up as such

```
Folder A
    Folder B1
      Folder C1
        file.mpg
    Folder B2
      Folder C2
        file.mpg
    Folder B3
      Folder C3
        file.mpg
```
What I want to do is take the .mpg files and move them all into Folder A. I know I'll have to use find, probably xargs, and *mpg 

Why it was ever set up as such in the first pace, I don't know.


----------



## wblock@ (Jun 3, 2013)

find(1) should be enough all by itself.  Use -exec rather than xargs(1).

But first, find out why the directories (not folders, actually) were set up that way.  There may be a reason that is not immediately obvious, like limiting the number of files per directory for performance.


----------



## th0r0din50n (Jun 3, 2013)

That may have been why, but everything is being moved to a new machine which significantly better performance. The new machine is still in a testing environment, so everything on the old one isn't being touched as of yet. I'm pretty sure this new one could easily handle the new directory structure, but not being sure is what testing environments are for! I'll mark it as solved here in a bit provided I get it to work. Should be able to give it a try here in a bit.


----------



## fluca1978 (Jun 4, 2013)

Should be something simple as (not tested):

```
find FolderA -name '*.mpg' -execdir mv {} FolderA \;
```

as suggested, using find(1) by its own should suffice. Moreover, the web is full of this kind of examples, so you should try to do your homework first.


----------

