Mail Archives: cygwin/2005/01/13/08:14:11
Until recently, I was using something like "find x -printf '%TT'" to
print the modification times for several files at once, but since I
installed findutils version 4.2.10-3 on 12/7/04, this hasn't worked. It
now prints a ten-digit number which seems to be the number of seconds
since 1/1/1970, instead of the 24-hour time as hh:mm:ss, as the info
documentation says it should.
In fact, a few of the time formats in find don't work as documented
anymore. Here are all the time formats for find in the order they are
documented in find.info, with descriptions from find.info pasted next to
the formats that didn't work:
$ for fmt in H I k l p Z M S @ a A b h B m d w j U W Y y r T X c D x +
> do echo "$fmt: `find /etc/passwd -printf \"%T$fmt\"`"
> done
H: 15
I: 03
k: 15
l: 3
p: PM
Z: EDT
M: 36
S: 42
@: 1097523402
a: Mon
A: Monday
b: Oct
h: Oct
B: October
m: 10
d: 11
w: 1
j: 285
U: 41
W: 41
Y: 2004
y: 04
r: 1097523402 time, 12-hour (hh:mm:ss [AP]M)
T: 1097523402 time, 24-hour (hh:mm:ss)
X: 15:36:42
c: Mon Oct 11 15:36:42 2004
D: 1097523402 date (mm/dd/yy)
x: Mon Oct 11 2004
+: + Date and time, separated by '+'
The function format_date in pred.c in the find source code simply hands
the time format to strftime, except that it handles the @ format itself,
and it changes the format "%+" to "%F+%T" before sending it to strftime.
However, strftime doesn't understand "%F+%T" either. The k, l, @, r, T,
D, and + formats are not documented for the strftime function in libc,
but strftime does understand k and l as hours on the 24-hour and 12-hour
clocks.
The date command handles all the formats find does except @ (date's
version is %s), but it also handles D and T correctly:
$ for fmt in H I k l p Z M S @ a A b h B m d w j U W Y y r T X c D x +
> do echo "$fmt: `date -r /etc/passwd +%$fmt`"
> done
H: 15
I: 03
k: 15
l: 3
p: PM
Z: EDT
M: 36
S: 42
@: %@
a: Mon
A: Monday
b: Oct
h: Oct
B: October
m: 10
d: 11
w: 1
j: 285
U: 41
W: 41
Y: 2004
y: 04
r:
T: 15:36:42
X: 15:36:42
c: Mon Oct 11 15:36:42 2004
D: 10/11/04
x: Mon Oct 11 2004
+: %+
Finally, I wrote a program to see which formats worked in the strftime
function, regardless of what the documentation says:
#include <stdio.h>
#include <time.h>
main (int cArgs, const char *asArg[])
{
time_t t;
struct tm *ptmLocal;
char s[80];
t = time(NULL);
ptmLocal = localtime(&t);
strftime(s, sizeof(s), asArg[1], ptmLocal);
printf("%s\n", s);
}
Here are the results:
$ for fmt in H I k l p Z M S @ a A b h B m d w j U W Y y r T X c D x +
> do echo "$fmt: `./tm %$fmt`"
> done
H: 14
I: 02
k: 14
l: 2
p: PM
Z: EST
M: 42
S: 37
@:
a: Wed
A: Wednesday
b: Jan
h: Jan
B: January
m: 01
d: 12
w: 3
j: 012
U: 02
W: 02
Y: 2005
y: 05
r:
T:
X: 14:42:38
c: Wed Jan 12 14:42:38 2005
D:
x: Wed Jan 12 2005
+:
Oddly enough, the D and T formats work for the date command, but not
with the strftime function. Either date does its own formating in these
cases, or date hasn't been built in a while. Neither date nor strftime
handles the r format correctly, although "date --help" says %r is the
12-hour time.
I have been using find's T format rather than X, because the
documentation seems to indicate that T is independent of the locale.
Apparently, it would print hh:mm:ss even in Germany, where they use
periods as the separators in the time string.
Naturally, I can work around this by using different formats with the
find command. I just wondered if anyone had noticed that find hasn't
matched its documentation since version 4.2.10-3 on 12/7/04.
Particularly, the formats %Tr, %TT, %TD, and %T+ don't work anymore. The
real problem may be deeper down in the strftime function in libc.
Steve Munson
Steve Munson
stevebm AT sprynet DOT com
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
- Raw text -