Martin McCormick wrote:

date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s" >f0
date +%s >f1

        What does the long form of this command give us that
date +%s fails to do?

It's a contrived example:

date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s"
  -j says "don't alter the system date" -- this is used if you want
     to read and format a date/time string other than the present time.

  -f says use the following format to read the input date. That's
     %a -- abbreviated weekday name (localized)
     %b -- abbreviated month name (localized)
     %d -- day of month as decimal number, zero padded to two digits
     %T -- equivalent to %H:%M:%S
         %H -- Hour in 24h clock, zero padded to two digits
         %M -- Minute, zero padded
         %S -- Second, zero padded
     %Z -- Time zone name
     %Y -- Year as 4 digits including century.
     (See strftime(3))

    Which looks like this:

    % date +"%a %b %d %T %Z %Y"
    Thu Sep 17 06:31:15 BST 2009

    and that just happens to be the default *output* format date produces
    without any arguments.  Which is appropriate as the next item on the command
    line is

 "`date`"  Rune the date command without arguments and substitute the output
    into the command line here as a single argument

  +%s finally, says output the date that was read in as the number of seconds
    since the epoch.  This is an argument to the initial date command.

so the end result is that the command reads the current date time in the 
output format, parses all of that then converts it into seconds-since-the-epoch,
using two invocations of the date(1) program to do so. Which is not at all 
if all you need to do is generate the current epoch time.  Just use

  date +%s

for that.

On the other hand, it does show you how to convert an arbitrary date/time to epoch time. eg.:

  % date -j -f "%a %b %d %T %Z %Y" "Fri Feb 13 23:31:30 GMT 2009" +%s



Dr Matthew J Seaman MA, D.Phil.                   7 Priory Courtyard
                                                 Flat 3
PGP:     Ramsgate
                                                 Kent, CT11 9PW

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to