title: How can I sort a directory by creation date in BASH?
body: <p>I'm trying to create a simple script to list the 16 most recent folders created in a directory  on my nas machine as a way to display the most recent movies added to my collection.</p>
  
  <p>the script i am using at the moment is:</p>
  
  <pre><code>#!/bin/bash
  rm -f /volume1/new-movies/*
  IFS=$'\x0A'
  fresh=$(ls -1ct /volume1/movies | head -16)
  for folder in $fresh
  do
      file=$(find "/volume1/movies/$folder" -maxdepth 1 -type f)
      movie=$(basename "$file")
      ln -s "$file" "/volume1/new-movies/$movie"
  done
  ls -1 /volume1/new-movies
  </code></pre>
  
  <p>which is OK (the movies folder will only ever contain folders). My problem is this is sorted by the file/folders modification time rather than the creation time. </p>
  
  <p>the filesystem is <code>ext4</code> and should support a <code>birth time</code> but i have had no luck accessing it.</p>
  
  <pre><code>scott@pandora scripts $ stat  /volume1/movies/example/
    File: '/volume1/movies/example/'
    Size: 4096            Blocks: 8          IO Block: 4096   directory
  Device: 902h/2306d      Inode: 373800961   Links: 2
  Access: (0755/drwxr-xr-x)  Uid: ( 1028/   scott)   Gid: (  100/   users)
  Access: 2013-04-09 13:39:53.243991684 +1000
  Modify: 2013-04-06 13:26:00.965998952 +1100
  Change: 2013-04-09 11:46:23.280991727 +1000
   Birth: -
  </code></pre>
  
  <p>however, samba seems to have no issue displaying the correct creation date/time. is there a way to access the same information from bash? or am i going to have to program something in python/other to do what i need by accessing smb directly and listing each folder with the creation date?</p>
  
  <pre><code>scott@pandora scripts $ smbclient \\\\localhost\\movies\\
  Enter scott's password:
  Domain=[EXAMPLENET] OS=[Unix] Server=[Samba 3.6.9]
  smb: \&gt; allinfo "example"
  altname: E06KNE~A
  create_time:    Fri Jun 18 17:23:49 2010 EST
  access_time:    Tue Apr  9 13:39:53 2013 EST
  write_time:     Sat Apr  6 13:26:01 2013 EST
  change_time:    Sat Apr  6 13:26:01 2013 EST
  attributes: DA (30)
  smb: \&gt; quit
  </code></pre>
  
  <p><strong>edit: see my below answer for my final solution to this issue.</strong></p>