title: How to find the latest folder in a directory and then make a full path accordingly?
body: <p>I have a directory which will have some folders and some files within it. Suppose this is my current directory as shown below with <code>pwd</code> command - </p>
  
  <pre><code>david@slc4b03c:/bat/data/snapshot$ pwd
  /bat/data/snapshot
  </code></pre>
  
  <p>And I am logged into <code>machineA</code>.</p>
  
  <p>This <code>/bat/data/snapshot</code> directory will have some folders and some files within it as shown below - </p>
  
  <pre><code>david@slc4b03c:/bat/data/snapshot$ ls -lt
  total 22400264
  drwxr-xr-x 2 cronusapp app   102400 2013-12-22 04:01 20131222
  drwxr-xr-x 2 cronusapp app   102400 2013-12-16 03:00 20131215
  -rw-r--r-- 1 cronusapp app 26412620 2013-12-13 02:04 weekly_003_5.data
  -rw-r--r-- 1 cronusapp app 26492037 2013-12-13 02:02 weekly_003_5.data
  -rw-r--r-- 1 cronusapp app 26480695 2013-12-13 02:02 weekly_003_5.data
  -rw-r--r-- 1 cronusapp app 26475266 2013-12-13 02:02 weekly_003_5.data
  -rw-r--r-- 1 cronusapp app 26471366 2013-12-13 02:02 weekly_003_5.data
  -rw-r--r-- 1 cronusapp app 26455311 2013-12-13 02:02 weekly_003_5.data
  </code></pre>
  
  <p>So the two folders I have is <code>20131222</code> and <code>20131215</code> as shown above.. Now I want to extract the latest folder from it, which will be <code>20131222</code> as it is more recent as compared to <code>20131215</code> and then make a full path like this - </p>
  
  <pre><code>/bat/data/snapshot/20131222/
  </code></pre>
  
  <p>As I need to use this full path while doing the scp from that machine to another machine,</p>
  
  <p>Below is my shell script in which I have hardcoded the recent path currently with <code>20131222</code> but in general, I need to make the full path by seeing which folder is the latest one by using the below shell script..</p>
  
  <pre><code>#!/bin/bash
  
  readonly LOCATION=/bat/data/snapshot
  
  scp david@slc4b03c.slc.host.com:/bat/data/snapshot/20131222/weekly_003_5.data /data01/primary/.
  </code></pre>
  
  <p>The above shell script I won't be running from the machineA. I will be running from different machine, let' say it is <code>machineB</code>.</p>
  
  <p>Is it possible to do this in shell script?</p>