title: Need to move a limited # of files on MacOs
body: <p>I have a requirement to move files from my local MacBook to a remote server using sftp.</p>
  
  <p>I need to take about 6000 files and move them to the remote server for processing. Due to limitations on the processing system, I can only process a maximum of 100 files at a time. The processing system will bomb if there are more than 100 files in the folder it monitors.</p>
  
  <p>I'd like to set up a script so that will run via crontab every x # of minutes and move 100 files from the folder on the Mac that contains the 6,500 files to a 'staging' folder.  Then a 2nd script would pick up and upload the contents of the 'staging' folder to the sftp folder.</p>
  
  <p>I've got the crontab working fine, however, I can't figure out how to limit the # of files I move to 100.</p>
  
  <p>Here's what I've done thus far.  Maybe I'm doing this completely wrong, so any suggestions would be appreciated!</p>
  
  <pre><code>#!/bin/bash
  cd /Users/Me/Downloads/test
  # Get files from unprocessed where the 6k files are located.
  </code></pre>
  
  <h1>the 'ls' command returns a '-bash: /bin/ls: Argument list too long' error</h1>
  
  <pre><code>ls unprocessed/*.pdf | head -n 99 &gt; flist
   while read f
     do
      mv "$f" .
   done &lt; flist
  </code></pre>
  
  <h1>this script would upload it to the sftp server.</h1>
  
  <p>./exp.sh</p>
  
  <h1>this would move it to a separate folder as it completes</h1>
  
  <pre><code>for f in *PAY*.pdf
   do
     mv "$f" processed/
  done
  </code></pre>
  
  <p>Any help would be appreciated! </p>