title: Move files based on directory name (Linux / Debian / #!)
body: <p><strong>Question:</strong></p>
  
  <p>How do I move files from many sub-directories with the same name to a single directory of that name. All files in multiple directories named X should get moved together into one directory named X. </p>
  
  <p><strong>Example file structure:</strong> </p>
  
  <p>(The real structure is 200-300 directories at the level I've marked as 1, 2, 3, etc., with varying numbers of directories below that.)</p>
  
  <p>(Note all labels like Group _ are just that--labels. The actual names are irregular.)</p>
  
  <ul>
  <li><p>Disk</p>
  
  <ul>
  <li><p>1</p>
  
  <ul>
  <li>Library
  <ul>
  <li>Music
  <ul>
  <li>Group A
  <ul>
  <li>Files</li>
  <li>Files</li>
  <li>Files</li>
  </ul></li>
  <li>Group B
  <ul>
  <li>Files</li>
  <li>Files</li>
  <li>Files</li>
  </ul></li>
  </ul></li>
  </ul></li>
  </ul></li>
  <li><p>2</p>
  
  <ul>
  <li>Library
  <ul>
  <li>Music
  <ul>
  <li>Group B
  <ul>
  <li>Files</li>
  <li>Files</li>
  <li>Files</li>
  </ul></li>
  <li>Group C
  <ul>
  <li>Files</li>
  <li>Files</li>
  <li>Files</li>
  </ul></li>
  </ul></li>
  </ul></li>
  </ul></li>
  <li>3
  <ul>
  <li>Library
  <ul>
  <li>Music
  <ul>
  <li>Group C
  <ul>
  <li>Files</li>
  <li>Files</li>
  <li>Files</li>
  </ul></li>
  <li>Group D
  <ul>
  <li>Files</li>
  <li>Files</li>
  <li>Files</li>
  </ul></li>
  </ul></li>
  </ul></li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>The goal is to have files in various sub-directories with name "Group X" moved into a <strong>single</strong> directory with name "Group X", like so:</p>
  
  <ul>
  <li>Disk
  <ul>
  <li>1
  <ul>
  <li>Library
  <ul>
  <li>Music
  <ul>
  <li>Group A
  <ul>
  <li>Files</li>
  <li>Files</li>
  <li>Files</li>
  </ul></li>
  <li>Group B
  <ul>
  <li>Files</li>
  <li>Files</li>
  <li>Files</li>
  <li>Files</li>
  <li>Files</li>
  <li>Files</li>
  </ul></li>
  <li>Group C
  <ul>
  <li>Files</li>
  <li>Files</li>
  <li>Files</li>
  <li>Files</li>
  <li>Files</li>
  <li>Files</li>
  </ul></li>
  <li>Group D
  <ul>
  <li>Files</li>
  <li>Files</li>
  <li>Files</li>
  </ul></li>
  </ul></li>
  </ul></li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>Thanks!</p>