title: Find most recently added file in current directory
body: <p>So I got this working locally but it's not working on my server.  Is the problem due to me using the <code>scp</code> command to transfer my files up to the server?</p>
  
  <p>Here's my code:</p>
  
  <pre><code>// Local
  if ('localhost' == $_SERVER['HTTP_HOST']) {
      $cmd = 'find resume*.pdf -type f -print0 | xargs -0 stat -f "%m %N" |sort -rn | head -1 | cut -f2- -d" "';
  // Production
  } else {
      $cmd = 'find resume*.pdf -type f -print0 | xargs -0 ls -drt | tail -n 1';
  }
  $results = exec($cmd);
  echo '$results = ' . $results;
  </code></pre>
  
  <p>Local Output:</p>
  
  <pre><code>$ php -f index.php
  $ $results = resume june 2014.pdf
  </code></pre>
  
  <p>Remote Output:</p>
  
  <pre><code>$ php -f index.php
  $ $results = resume_may_2014.pdf
  </code></pre>
  
  <p>Here's what it looks like when I look at the modification dates of the files on the server. <strong>I also can't figure out why they (as in the resume files with the same modification date) are getting ordered this way.</strong> It's not like they are sorted by alphabetical, file size, etc.</p>
  
  <pre><code>&lt;!-- language: lang-bash --&gt;
  username@username.com [~/www/resume]# ls -lt
  total 432
  drwxr-xr-x  6 username username   4096 Jun  1 14:05 ./
  -rw-r--r--  1 username username    927 Jun  1 14:00 index.php
  -rw-r--r--  1 username username   2028 Jun  1 13:55 error_log
  -rw-r--r--  1 username username 135855 Jun  1 13:37 resume_may_2014.pdf
  -rw-r--r--  1 username username      0 Jun  1 13:37 resume_feb_2014.pdf
  -rw-r--r--  1 username username 118698 Jun  1 13:37 resume\ june\ 2014.pdf
  drwxr-xr-x  4 username username   4096 Jun  1 13:18 resume\ june\ 2014.pages/
  -rw-r--r--  1 username username 135855 May 31 18:59 resume.pdf
  </code></pre>
  
  <p>Articles Referenced:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/4561895/how-to-recursively-find-the-latest-modified-file-in-a-directory">How to recursively find the latest modified file in a directory?</a></li>
  <li><a href="http://mywiki.wooledge.org/BashFAQ/003" rel="nofollow noreferrer">How can I find the latest (newest, earliest, oldest) file in a directory</a></li>
  </ul>