[sf-lug] I need a quick piece of code..

Rick Moen rick at linuxmafia.com
Thu Dec 31 14:28:55 PST 2009

Quoting Jim Stockford (jim at well.com):

> hmmm. 
> tail -1 filename 
> tail -n 1 filename 
> tail --lines=1 filename 
> so many choices. i wonder why. 
>    also, tho' neither the --help nor the man page 
> mentions it, tail -1 (or any other number) works. 

The thing about options unmentioned in manpages is that they are prone
to suddenly ceasing to work, at unpredictable times, following upgrade -- 
or working on some systems but not others.  I learned this with the old
"date -I" command of blessed memory, which used to produce date output
in ISO 8601 format, like "2009-12-31".  In fact, that was a shorthand
equivalent of "date --iso-8601", except much easier to remember.

What's attractive about ISO 8601 date format is that it sorts properly,
e.g., when you do "program > /var/log/programlog-$(date -I)".

But then, both of those options disappeared from the manpage.  And then,
both started not working on some Linux distributions (RHEL) but working
on others (Debian), depending on whether the distro had updated GNU
coreutils to pick up upstream changes to the date command.

What had happened inside the GNU coreutils project, but unnoticed by
most of us, is that the upstream maintainers had first introduced
--rfc-3339 (obviously, not easy to remember, either) -- for the
questionable reason of ISO 8601 being a profile of RFC 3339.  Option
-i was proposed as a replacement short option (standing for 'Internet
time'), but rejected because Paul Eggert's PC clock was too jittery

Anyway, the fact that "-I" suddenly disappeared from the manpage was a
big clue that you'd be wise to stop relying on it.  Turned out, the 
least-annoying replacement syntax was:

date +%F

Rick Moen              "Having the right word is much more satisfying than just 
rick at linuxmafia.com    sleeping around with any old word that comes along."
                                                            -- FakeAPStylebook

More information about the sf-lug mailing list