[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is there a way to increment the time for n seconds?

From: Bob Proulx
Subject: Re: Is there a way to increment the time for n seconds?
Date: Tue, 11 Sep 2001 15:00:15 -0600


> Is there a way to increment the time for n seconds? I am thinking something 
> like
> # touch -F n foo
> which will increment the time by n seconds and
> # touch -B n foo
> which will decrement the time by n seconds.

When you say increment, do you mean of the clock time or of the file
timestamp time?  I will assume you mean filestamp time.  And of course
I am curious as to your application for this.

Since you suggested incrementing and decrementing by seconds I assume
seconds as well.  But check out the date string parsing capability of
both date and touch for more ideas.  You can do some very fun things
using GNU extensions.  Try these.  Every time this command sequence is
called it will increment the timestamp of the file.

  oldstamp=$(date -r foo +%s)
  newstamp=$(expr $oldstamp + 10)
  newtime=$(date -u -d "1970-01-01 $newstamp sec UTC")
  touch --date="$newtime" foo

And of course the entire thing can be compressed into one line.

  touch --date="$(date -u -d "1970-01-01 $(expr $(date -r foo +%s) + 10) sec 
UTC")" foo

Hmm...  It would be convenient to be able to combine date -r with date
--time and do a super case of what you want.  This would read much
more simply.  But that currently is not available.

  touch --date="$(date -r foo --date='10 seconds')"  # does not work

Also, make sure you have a recent version of date.  There have been
several bugs in the date code fixed just before Y2K.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]