Re: Exact timestamp for sorting and renaming files according to creation order

2012-01-04 Thread Polytropon
On Wed, 04 Jan 2012 15:01:32 +0100, Julian H. Stacey wrote:
> Hi,
> Devin Teske wrote:
> > > -Original Message-
> > > From: owner-freebsd-questi...@freebsd.org [mailto:owner-freebsd-
> > > questi...@freebsd.org] On Behalf Of Polytropon
> > > Sent: Tuesday, January 03, 2012 1:00 PM
> > > To: Dan Nelson
> > > Cc: FreeBSD Questions
> > > Subject: Re: Exact timestamp for sorting and renaming files according to
> > creation
> > > order
> > > 
> > > On Tue, 3 Jan 2012 14:49:02 -0600, Dan Nelson wrote:
> > > > If you ask for the date to be printed in "float" (F) format, it gives
> > > > more precision.  The default is unsigned int (U) format.
> > > >
> > > > % stat -f "%N %FB" /COPYRIGHT
> > > > /COPYRIGHT 1306190895.046721049
> > > 
> > > Strangely, I only get a 0 "suffix" for any time stamp, no matter 
> > > if I
> > create
> > > the file or apply the command as shown above to an existing file:
> > > 
> > >   % stat -f "%N %FB" /COPYRIGHT
> > >   /COPYRIGHT 1313951230.0
> > > 
> > > Am I missing some file system feature?
> > > 
> > > Otherwise, this _exactly_ looks like what I'm searching for. It doesn't 
> > > need
> > to be
> > > a "human-readable" date representation.
> > > 
> > > by the way, I'm running FreeBSD 8.2-STABLE/x86 of late August 2011 here, 
> > > file
> > > system used is UFS2.
> > 
> > On ZFS, all is well...
> > 
> > % df -hT /raid1/jails/package8-1/COPYRIGHT
> > Filesystem  TypeSizeUsed   Avail Capacity  Mounted on
> > raid1/jails/package8-1  zfs 835G672M835G 0%
> > /raid1/jails/package8-1
> > 
> > % stat -f "%N %FB" /raid1/jails/package8-1/COPYRIGHT
> > /raid1/jails/package8-1/COPYRIGHT 1324356049.328275367
> > 
> > But alas, on UFS2:
> > 
> > % df -hT /COPYRIGHT
> > Filesystem TypeSizeUsed   Avail Capacity  Mounted on
> > /dev/mfid0s1a  ufs 989M 64M846M 7%/
> > 
> > % stat -f "%N %FB" /COPYRIGHT
> > /COPYRIGHT 1279505857.0

The idea of changing the sysctl vfs.timestamp_precision
to the value 3 worked on UFS for me. But it doesn't seem
to be the default.

Another problem might be when dealing with files that are
stored on a filesystem type different from UFS...



> I was wondering how df (& stat) could show more than seconds
> (Remembering back to 1990 & my
>   http://berklix.com/~jhs/src/bsd/jhs/bin/public/statv/
>   when Unix used unsigned long seconds since 1 jan 1970
>   ( & MSDOS was seconds divided by 2 since 1 jan 1980 )
>   )
> FreeBSD 8.2-RELEASE /usr/src/usr.bin/stat/stat.c
> line 320 etc still uses the normal fstat stat lstat.
> But man 2 stat has extended :
>  #ifndef _POSIX_SOURCE
>  #define st_atime st_atimespec.tv_sec
>  #define st_mtime st_mtimespec.tv_sec
>  #define st_ctime st_ctimespec.tv_sec
>  #endif

The st_birthtime field would be the required one for
sorting here (and defaults, per definition, to seconds).
The "man 1 stat" mentions that stat uses the stat and
lstat system system calls, so this would be the value
that will be retrieved of no "finer time" can be
accessed (which would mean zeros here).



> cd /usr/include/sys ; vi -c/tv_sec /types.h stat.h
> #if __BSD_VISIBLE
> #define st_atime st_atimespec.tv_sec
> structtimespec
> #include 
> time.h:   #include 
> timespec.h:
> struct timespec {time_t tv_sec;/* seconds */ long tv_nsec;/* nanoseconds */};
> 
> I guess extended timespec may get compiled in to VFS but not UFS,
> but no time to look further, Good luck Polytropn.

At least that's a starting point. I see that changing
the sysctl mentioned above seems to be sufficient for
the current purpose. However, I'd like to see the system
defaulting (!) to a resolution better than seconds, as
this is definitely possible.



> PS Here with UFS (per Dan's tip, thanks) I see:
> sysctl vfs.timestamp_precision=2 ; stat -f "%N %FB" /etc/motd
>   /etc/motd 1306839862.0

That's understandable, as the "finer time" will
be generated only upon file _creation_; for files
that are already present, 0 is the typical
result.

# sysctl vfs.timestamp_precision=3
vfs.timestamp_precision: 0 -> 3

And then:

% touch hickup.txt
% stat -f "%N %FB" hickup.txt
hickup.txt 1325686735.035925369

In comparison:

% stat -f "%N %FB" /etc/motd
/etc/motd 1309547364.0

which has been created prior to changing the
vfs.timestamp_precision sysctl.



-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: Exact timestamp for sorting and renaming files according to creation order

2012-01-04 Thread Julian H. Stacey
Hi,
Devin Teske wrote:
> > -Original Message-
> > From: owner-freebsd-questi...@freebsd.org [mailto:owner-freebsd-
> > questi...@freebsd.org] On Behalf Of Polytropon
> > Sent: Tuesday, January 03, 2012 1:00 PM
> > To: Dan Nelson
> > Cc: FreeBSD Questions
> > Subject: Re: Exact timestamp for sorting and renaming files according to
> creation
> > order
> > 
> > On Tue, 3 Jan 2012 14:49:02 -0600, Dan Nelson wrote:
> > > If you ask for the date to be printed in "float" (F) format, it gives
> > > more precision.  The default is unsigned int (U) format.
> > >
> > > % stat -f "%N %FB" /COPYRIGHT
> > > /COPYRIGHT 1306190895.046721049
> > 
> > Strangely, I only get a 0 "suffix" for any time stamp, no matter if 
> > I
> create
> > the file or apply the command as shown above to an existing file:
> > 
> > % stat -f "%N %FB" /COPYRIGHT
> > /COPYRIGHT 1313951230.0
> > 
> > Am I missing some file system feature?
> > 
> > Otherwise, this _exactly_ looks like what I'm searching for. It doesn't need
> to be
> > a "human-readable" date representation.
> > 
> > by the way, I'm running FreeBSD 8.2-STABLE/x86 of late August 2011 here, 
> > file
> > system used is UFS2.
> 
> On ZFS, all is well...
> 
> % df -hT /raid1/jails/package8-1/COPYRIGHT
> Filesystem  TypeSizeUsed   Avail Capacity  Mounted on
> raid1/jails/package8-1  zfs 835G672M835G 0%
> /raid1/jails/package8-1
> 
> % stat -f "%N %FB" /raid1/jails/package8-1/COPYRIGHT
> /raid1/jails/package8-1/COPYRIGHT 1324356049.328275367
> 
> But alas, on UFS2:
> 
> % df -hT /COPYRIGHT
> Filesystem TypeSizeUsed   Avail Capacity  Mounted on
> /dev/mfid0s1a  ufs 989M 64M846M 7%/
> 
> % stat -f "%N %FB" /COPYRIGHT
> /COPYRIGHT 1279505857.0
> 
> -- 
> Devin

I was wondering how df (& stat) could show more than seconds
(Remembering back to 1990 & my
http://berklix.com/~jhs/src/bsd/jhs/bin/public/statv/
when Unix used unsigned long seconds since 1 jan 1970
( & MSDOS was seconds divided by 2 since 1 jan 1980 )
)
FreeBSD 8.2-RELEASE /usr/src/usr.bin/stat/stat.c
line 320 etc still uses the normal fstat stat lstat.
But man 2 stat has extended :
 #ifndef _POSIX_SOURCE
 #define st_atime st_atimespec.tv_sec
 #define st_mtime st_mtimespec.tv_sec
 #define st_ctime st_ctimespec.tv_sec
 #endif

cd /usr/include/sys ; vi -c/tv_sec /types.h stat.h
#if __BSD_VISIBLE
#define st_atime st_atimespec.tv_sec
struct  timespec
#include 
time.h: #include 
timespec.h:
struct timespec {time_t tv_sec;/* seconds */ long tv_nsec;/* nanoseconds */};

I guess extended timespec may get compiled in to VFS but not UFS,
but no time to look further, Good luck Polytropn.

PS Here with UFS (per Dan's tip, thanks) I see:
sysctl vfs.timestamp_precision=2 ; stat -f "%N %FB" /etc/motd
/etc/motd 1306839862.0

Cheers,
Julian
-- 
Julian Stacey, BSD Unix Linux C Sys Eng Consultants Munich http://berklix.com
 Reply below not above, cumulative like a play script, & indent with "> ".
 Format: Plain text. Not HTML, multipart/alternative, base64, quoted-printable.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: Exact timestamp for sorting and renaming files according to creation order

2012-01-03 Thread Dan Nelson
In the last episode (Jan 03), Polytropon said:
> On Tue, 3 Jan 2012 14:49:02 -0600, Dan Nelson wrote:
> > If you ask for the date to be printed in "float" (F) format, it gives
> > more precision.  The default is unsigned int (U) format.
> > 
> > % stat -f "%N %FB" /COPYRIGHT 
> > /COPYRIGHT 1306190895.046721049
> 
> Strangely, I only get a 0 "suffix" for any
> time stamp, no matter if I create the file or apply
> the command as shown above to an existing file:
> 
>   % stat -f "%N %FB" /COPYRIGHT 
>   /COPYRIGHT 1313951230.0
> 
> Am I missing some file system feature?
> 
> Otherwise, this _exactly_ looks like what I'm searching for.  It doesn't
> need to be a "human-readable" date representation.
> 
> by the way, I'm running FreeBSD 8.2-STABLE/x86 of late August 2011 here,
> file system used is UFS2.

Try raising the vfs.timestamp_precision sysctl above zero.  That gives me
useful fractional values on ufs.

% sysctl -d vfs.timestamp_precision
vfs.timestamp_precision: File timestamp precision (
0: seconds, 
1: sec + ns accurate to 1/HZ, 
2: sec + ns truncated to ms, 
3+: sec + ns (max. precision))

-- 
Dan Nelson
dnel...@allantgroup.com
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


RE: Exact timestamp for sorting and renaming files according to creation order

2012-01-03 Thread Devin Teske


> -Original Message-
> From: owner-freebsd-questi...@freebsd.org [mailto:owner-freebsd-
> questi...@freebsd.org] On Behalf Of Polytropon
> Sent: Tuesday, January 03, 2012 1:00 PM
> To: Dan Nelson
> Cc: FreeBSD Questions
> Subject: Re: Exact timestamp for sorting and renaming files according to
creation
> order
> 
> On Tue, 3 Jan 2012 14:49:02 -0600, Dan Nelson wrote:
> > If you ask for the date to be printed in "float" (F) format, it gives
> > more precision.  The default is unsigned int (U) format.
> >
> > % stat -f "%N %FB" /COPYRIGHT
> > /COPYRIGHT 1306190895.046721049
> 
> Strangely, I only get a 0 "suffix" for any time stamp, no matter if I
create
> the file or apply the command as shown above to an existing file:
> 
>   % stat -f "%N %FB" /COPYRIGHT
>   /COPYRIGHT 1313951230.0
> 
> Am I missing some file system feature?
> 
> Otherwise, this _exactly_ looks like what I'm searching for. It doesn't need
to be
> a "human-readable" date representation.
> 
> by the way, I'm running FreeBSD 8.2-STABLE/x86 of late August 2011 here, file
> system used is UFS2.

On ZFS, all is well...

% df -hT /raid1/jails/package8-1/COPYRIGHT
Filesystem  TypeSizeUsed   Avail Capacity  Mounted on
raid1/jails/package8-1  zfs 835G672M835G 0%
/raid1/jails/package8-1

% stat -f "%N %FB" /raid1/jails/package8-1/COPYRIGHT
/raid1/jails/package8-1/COPYRIGHT 1324356049.328275367

But alas, on UFS2:

% df -hT /COPYRIGHT
Filesystem TypeSizeUsed   Avail Capacity  Mounted on
/dev/mfid0s1a  ufs 989M 64M846M 7%/

% stat -f "%N %FB" /COPYRIGHT
/COPYRIGHT 1279505857.0

-- 
Devin



> 
> 
> 
> 
> --
> Polytropon
> Magdeburg, Germany
> Happy FreeBSD user since 4.0
> Andra moi ennepe, Mousa, ...
> ___
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscr...@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.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: Exact timestamp for sorting and renaming files according to creation order

2012-01-03 Thread Polytropon
On Tue, 3 Jan 2012 14:49:02 -0600, Dan Nelson wrote:
> If you ask for the date to be printed in "float" (F) format, it gives more
> precision.  The default is unsigned int (U) format.
> 
> % stat -f "%N %FB" /COPYRIGHT 
> /COPYRIGHT 1306190895.046721049

Strangely, I only get a 0 "suffix" for any
time stamp, no matter if I create the file or apply
the command as shown above to an existing file:

% stat -f "%N %FB" /COPYRIGHT 
/COPYRIGHT 1313951230.0

Am I missing some file system feature?

Otherwise, this _exactly_ looks like what I'm searching
for. It doesn't need to be a "human-readable" date
representation.

by the way, I'm running FreeBSD 8.2-STABLE/x86 of
late August 2011 here, file system used is UFS2.




-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


RE: Exact timestamp for sorting and renaming files according to creation order

2012-01-03 Thread Devin Teske


> -Original Message-
> From: owner-freebsd-questi...@freebsd.org [mailto:owner-freebsd-
> questi...@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
creation
> 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
precision.
> 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.
-- 
Devin

> 
> > 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
>   dnel...@allantgroup.com
> ___
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscr...@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.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: Exact timestamp for sorting and renaming files according to creation order

2012-01-03 Thread Dan Nelson
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
precision.  The default is unsigned int (U) format.

% stat -f "%N %FB" /COPYRIGHT 
/COPYRIGHT 1306190895.046721049

> 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
dnel...@allantgroup.com
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Exact timestamp for sorting and renaming files according to creation order

2012-01-03 Thread Polytropon
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

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?


-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"