title: Shell script to sort & mv file based on date
body: <p>Im new to unix,I have search a lot of info but still don not how to make it in a bash        </p>
  
  <p>What i know is used this command <code>ls -tr|xargs -i ksh -c "mv {} ../tmp/"</code> to move file by file.    </p>
  
  <p>Now I need to make a script that sorts all of these files by system date and moves them into a directory, The first 1000 oldest files being to be moved.       </p>
  
  <p>Example files r like these        </p>
  
  <p><code>KPK.AWQ07102011.66.6708.01</code><br>
  <code>KPK.AWQ07102011.68.6708.01</code><br>
  <code>KPK.EER07102011.561.8312.13</code><br>
  <code>KPK.WWS07102011.806.3287.13</code>    </p>
  
  <p>-----------This is the script tat i hv been created-------</p>
  
  <pre><code>if [ ! -d /app/RAID/Source_Files/test/testfolder ] then    
                  echo "test directory does not exist!"    
                  mkdir /app/RAID/Source_Files/calvin/testfolder    
                  echo "unused_file directory created!"    
  fi
  
  echo "Moving xx oldest files to test directory"
  
  ls -tr  /app/RAID/Source_Files/test/*.Z|head -1000|xargs -i ksh -c "mv {} /app/RAID/Source_Files/test/testfolder/"
  </code></pre>
  
  <hr>
  
  <p>the problem of this script is<br>
  1) unix prompt a syntax erro 'if'<br>
  2) The move command is working but it create a new filename testfolder instead move to  directory testfolder (testfolder alredy been created in this path)</p>
  
  <p>anyone can gv me a hand ? thanks</p>