title: I would like to write a script that organizes my drum library
body: <p>So I would like to create a Bash script that organizes my Drum Library.  I would like to input the string 'kick' and have it recursively search a specified directory.  It should find all directories within the directory with the string 'kick' and copy its contents to a separate directory.  (Preferably emptying out the directory and not just copying the folder over).  I am running on Mac Terminal and I have included the code I have come up with so far but It is not doing exactly what I would like.  I think the problem lies in the line of code with 'find'</p>
  
  <p>Also in the new directory I'm grouping the final files in new directories by 128.</p>
  
  <pre><code>#!/bin/bash
  
  declare -i numFiles
  declare -i numDirs
  mkdir ./temp
  
  ceildivide(){
  local num
  num=$1
  echo $(( (num + 127) / 128 ))
  }
  
  find -E /Users/dot/Documents/_Sound\ Library/Drums\ \&amp;\ Samples -regex ".*$1.*" -exec cp {} ./temp/ \;
  
  numFiles=`ls ./temp | wc -l`
  numDirs=$(ceildivide $numFiles)
  
  for i in $(seq 1 $numDirs); do
     mkdir $1_$i;
      ls ./temp/ |head -n 128 &gt; $1_$i/$1_$i.index
              for x in `cat $1_$i/$1_$i.index`; do mv ./temp/$x $1_$i; done
  
  done
  
  rm -rf ./temp
  </code></pre>