title: Unique Linux filename, sortable by time
body: <p>Previously I was using <a href="http://man7.org/linux/man-pages/man1/uuidgen.1.html" rel="nofollow" title="uuidgen">uuidgen</a> to create unique filenames that I then need to iterate over by date/time via a bash script.  I've since found that simply looping over said files via 'ls -l' will not suffice because evidently I can only trust the OS to keep timestamp resolution in seconds (nonoseconds is all zero when viewing files via stat on this particular filesystem and kernel)</p>
  
  <p>So I then though maybe I could just use something like <code>date +%s%N</code> for my filename.  This will print the seconds since 1970 followed by the current nanoseconds.  </p>
  
  <p>I'm possibly over-engineering this at this point, but these are files generated on high-usage enterprise systems so I don't really want to simply trust the nanosecond timestamp on the (admittedly very small) chance two files are generated in the same nanosecond and we get a collision.</p>
  
  <p>I believe the uuidgen script has logic baked in to handle this occurrence so it's still guaranteed to be unique in that case (correct me if I'm wrong there... I read that someplace I think but the googles are failing me right now).</p>
  
  <p>So... I'm considering something like</p>
  
  <pre><code>FILENAME=`date +%s`-`uuidgen -t`
  echo $FILENAME
  </code></pre>
  
  <p>to ensure I create a unique filename that can then be iterated over with a simple 'ls' and who's name can be trusted to both be unique and sequential by time.  </p>
  
  <p>Any better ideas or flaws with this direction?</p>