title: I need to write a simple program that goes through a folder with subfolders and deletes the last file in each subfolder beneath the folder
body: <p>I searched through the site and found nothing like what I needed, so I decided to make my own question.</p>
  <p>I am using linux, trying to figure out a way to do what I described using tools like find, awk, rm, and others; but so far I have not been able to think of a way.</p>
  <p>A bit of background,</p>
  <ul>
  <li>The files are renamed in a neat alphabetical manner. No white space.</li>
  <li>Subfolders are named like that too.</li>
  <li>When I say last file, I mean the last file by alphabetical sorting.</li>
  <li>The amount of files in each subfolder is not same. Some subfolders have 56 files, while others don't even hit two digit. So I can't execute a convenient command like this:</li>
  </ul>
  <p><code>rm ./folder-*/020.jpg</code></p>
  <p>Which I would have been able to if all subfolders had the same amount of files in them.</p>
  <p>To illustrate the directory, it would be like</p>
  <pre><code>./original-folder
  ./original-folder/subfolder-001/001.jpg
  ./original-folder/subfolder-001/002.jpg
  ./original-folder/subfolder-001/003.jpg
  ./original-folder/subfolder-002/001.jpg
  ./original-folder/subfolder-002/002.jpg
  ./original-folder/subfolder-003/001.jpg
  </code></pre>
  <p>And so on.
  I want it to look like this basically</p>
  <pre><code>./original-folder
  ./original-folder/subfolder-001/001.jpg
  ./original-folder/subfolder-001/002.jpg
  ./original-folder/subfolder-002/001.jpg
  ./original-folder/subfolder-003/001.jpg
  </code></pre>
  <p>Note that last file is one less than before.</p>
  <p>My solution was to find a way to start a list every time the program went to a new folder, and then borrowing the last item of that list for rm command but I have absolutely 0 idea on how to do that within bash or anything.</p>
  <p>Feels like I need a fully functional programming language to do that.</p>