LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 08-28-2009, 03:39 PM   #1
Woodsman
Senior Member
 
Registered: Oct 2005
Distribution: Slackware 14.0
Posts: 3,476

Rep: Reputation: 531Reputation: 531Reputation: 531Reputation: 531Reputation: 531Reputation: 531
Changes in Latest Core Utils find/printf Command?


Today I ran a shell script I have been running for a few years in my Slackware machines. I ran the script in 13.0 and I received syntax error messages.

Eventually I found the problem with some data I was piping to the bc calculator command. The data is generated like this:

find /etc/hosts -printf "%TY%Tm%Td%TH%TM.%TS\n"

In previous versions the result was always something like this:

200908281437.19

In Current/13.0 the same syntax returns a result like this:

200908281437.19.0000000000

The bc command balks at the latter form of data.

What has changed with find/printf that the extraneous zeroes are being created? How do I stop that? I don't see anything obvious in the man page.

I can strip the zeroes but only if there is no other solution with the syntax.

Thanks.
 
Old 08-28-2009, 03:59 PM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
The change is due to the -printf predicate, but I don't think it has been introduced recently (at least in a wider perspective, not only about slackware). Here is what the GNU find manual says about this topic:
Quote:
The fractional part of the seconds field is of indeterminate length and precision. That is, the length of the fractional part of the seconds field will in general vary between findutils releases and between systems. This means that it is unwise to assume that field has any specific length. The length of this field is not usually a guide to the precision of timestamps in the underlying file system.
Indeed, I have always seen the second (fractional) form of %TS.
 
Old 08-28-2009, 04:21 PM   #3
Woodsman
Senior Member
 
Registered: Oct 2005
Distribution: Slackware 14.0
Posts: 3,476

Original Poster
Rep: Reputation: 531Reputation: 531Reputation: 531Reputation: 531Reputation: 531Reputation: 531
Solved

Thanks for the reply.

So you have always seen the fractional part of the seconds whereas I never have. Interesting.

Based upon what you wrote, additional searching revealed I can limit the fractional part of the seconds:

Was:
find /etc/hosts -printf "%TY%Tm%Td%TH%TM.%TS\n"

Change to:
find /etc/hosts -printf "%TY%Tm%Td%TH%TM.%.2TS\n"

Interestingly, that change in syntax seems to have no effect in 12.2 but works as I want in 13. I no longer have the extraneous zeroes when running the script in 13.

I wonder what changed in 13 to cause me to see the fractional seconds where I never saw them before?

Last edited by Woodsman; 08-28-2009 at 04:22 PM.
 
Old 08-28-2009, 04:36 PM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
Code:
find /etc/hosts -printf "%TY%Tm%Td%TH%TM.%.2TS\n"
That's interesting: I didn't know you can use number of digits with time modifiers! Thank you for this.

The Change Log of findutils is not very clear about the introduction (or modification) of the seconds modifier. It simply stats that the documentation has been improved to clarify the behaviour of the fractional part:
Quote:
2007-06-22 James Youngman <jay@gnu.org>

Better documentation for the fractional part of seconds fields for
-printf and similar actions.
* doc/find.texi (Time Components): Point out that the seconds
field of the timestamp is often printed out with a fractional part
of unspecified length and precision. The '%Tc' field has no
seconds part.
Quote:
2007-05-27 James Youngman <jay@gnu.org>
* doc/find.texi (Size Directives): Document the %S format
directive for -printf.
 
Old 08-28-2009, 04:52 PM   #5
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
Quote:
Originally Posted by Woodsman View Post
So you have always seen the fractional part of the seconds whereas I never have. Interesting.
Sorry. I have to correct my previous assertion: I've always seen the fractional part but I used time modifiers with -print in a couple of scripts running on Opensuse. Just out of curiosity, I checked on CentOS 5.3 and Fedora 9 and it shows the integer part only!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with printf command in C program snowman81 Programming 8 04-08-2008 12:12 AM
apt-get can't find latest FireFox. Fasn8n Ubuntu 7 03-15-2006 08:18 PM
how to find latest drivers? slinky2004 Linux - General 2 12-09-2005 06:48 PM
Where to find the latest logfile a1ex_007 Linux - Security 1 03-18-2005 09:58 PM
executing a command as part of printf... thatbloke Linux - Newbie 6 05-06-2004 04:15 PM


All times are GMT -5. The time now is 01:29 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration