Exact timestamp for sorting and renaming files according to creation order

Devin Teske devin.teske at fisglobal.com
Tue Jan 3 20:55:48 UTC 2012

> -----Original Message-----
> From: owner-freebsd-questions at freebsd.org [mailto:owner-freebsd-
> questions at freebsd.org] On Behalf Of Dan Nelson
> Sent: Tuesday, January 03, 2012 12:49 PM
> To: Polytropon
> Cc: FreeBSD Questions
> Subject: Re: Exact timestamp for sorting and renaming files according to
> order
> In the last episode (Jan 03), Polytropon said:
> > For a sorting script, I'm currently searching for a method to get file
> > creation date and time as exactly as possible.  The best resolution I
> > could get was seconds.  In case more than one file is created within
> > the same second, it doesn't work precisely enough.  It should work
> > from sh script.
> >
> > For the purpose of preparing the sort list (that will be sorted and
> > then be used as a template for renaming the files with a prefix and a
> > counter), I'm using the "stat" program which creates output like this:
> >
> > 	% stat -f "%N %B" -t "%Y-%m-%d_%H:%M:%S" 1.txt
> > 	1.txt 2012-01-03_12:12:12
> >
> > It's also possible to use the Epoch time format, but it doesn't
> > provide a solution better than seconds:
> >
> > 	% stat -f "%N %B" -t "%s" 1.txt
> > 	1.txt 1325589132
> If you ask for the date to be printed in "float" (F) format, it gives more
> The default is unsigned int (U) format.
> % stat -f "%N %FB" /COPYRIGHT
> /COPYRIGHT 1306190895.046721049

And you can specify "float precision" ...

% stat -f "%N %.2FB" /COPYRIGHT

Will return only 2 decimal places.

> > I've read the manuals for stat as well as for strftime (which is the
> > facility stat's -t parameter addresses), but found nothing that is
> > more precise than seconds.
> >
> > Does anyone have a suggestion how to precisely determine the order
> > files have been created?
> --
> 	Dan Nelson
> 	dnelson at allantgroup.com
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"

The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you.

More information about the freebsd-questions mailing list