title: command line find first file in a directory
body: <p>My directory structure is as follows</p>
  
  <pre><code>Directory1\file1.jpg
            \file2.jpg
            \file3.jpg
  
  Directory2\anotherfile1.jpg
            \anotherfile2.jpg
            \anotherfile3.jpg
  
  Directory3\yetanotherfile1.jpg
            \yetanotherfile2.jpg
            \yetanotherfile3.jpg
  </code></pre>
  
  <p>I'm trying to use the command line in a bash shell on ubuntu to take the first file from each directory and rename it to the directory name and move it up one level so it sits alongside the directory.</p>
  
  <p>In the above example:</p>
  
  <ul>
  <li><p><code>file1.jpg</code> would be renamed to <code>Directory1.jpg</code> and placed alongside the folder <code>Directory1</code></p></li>
  <li><p><code>anotherfile1.jpg</code> would be renamed to <code>Directory2.jpg</code> and placed alongside the folder Directory2</p></li>
  <li><p><code>yetanotherfile1.jpg</code> would be renamed to <code>Directory3.jpg</code> and placed alongside the folder <code>Directory3</code></p></li>
  </ul>
  
  <p>I've tried using: </p>
  
  <pre><code>find . -name "*.jpg"
  </code></pre>
  
  <p>but it does not list the files in sequential order (I need the first file).  </p>
  
  <p>This line:</p>
  
  <pre><code>find . -name "*.jpg" -type f -exec ls "{}" +;
  </code></pre>
  
  <p>lists the files in the correct order but how do I pick just the first file in each directory and move it up one level?</p>
  
  <p>Any help would be appreciated!</p>
  
  <p>Edit:  When I refer to the first file what I mean is each jpg is numbered from 0 to however many files in that folder - for example: file1, file2...... file34, file35 etc...  Another thing to mention is the format of the files is random, so the numbering might start at 0 or 1a or 1b etc...</p>