title: Terminal find, directories last instead of first
body: <p>I have a <code>makefile</code> that concatenates JavaScript files together and then runs the file through <code>uglify-js</code> to create a <code>.min.js</code> version.</p>
  
  <p>I'm currently using this command to find and concat my files</p>
  
  <pre><code>find src/js -type f -name "*.js" -exec cat {} &gt;&gt; ${jsbuild}$@ \;
  </code></pre>
  
  <p>But it lists files in directories first, this makes heaps of sense but I'd like it to list the <code>.js</code> files in the <code>src/js</code> files <strong>above</strong> the directories to avoid getting my <code>undefined</code> JS error.</p>
  
  <p>Is there anyway to do this or? I've had a google around and seen the <a href="https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/sort.1.html" rel="noreferrer"><code>sort</code></a> command and the <code>-s</code> flag for <code>find</code> but it's a bit above my understanding at this point!</p>
  
  <p><strong>[EDIT]</strong></p>
  
  <p>The final solution is slightly different to the accepted answer but it is marked as accepted as it brought me to the answer. Here is the command I used</p>
  
  <pre><code>cat `find src/js -type f -name "*.js" -print0 | xargs -0 stat -f "%z  %N" | sort -n | sed -e "s|[0-9]*\ \ ||"` &gt; public/js/myCleverScript.js
  </code></pre>