[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: |
H . J . Lu |
Subject: |
Re: Is there a way to increment the time for n seconds? |
Date: |
Tue, 11 Sep 2001 14:21:03 -0700 |
User-agent: |
Mutt/1.2.5i |
On Tue, Sep 11, 2001 at 03:00:15PM -0600, Bob Proulx wrote:
> H.J.
>
> > 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 meant the timestamp on the file.
> I am curious as to your application for this.
I have a source file, foo.p, and I do
# gen -o foo.c foo.p
which generates foo.c from foo.p. foo.p can be changed by other people
with the timestamp when the changed is made. I'd like to
# gen -o foo.c foo.p
# touch -r foo.p -F 1 foo.c
so that foo.c will be 1 second newer than foo.p. When foo.p is updated
with the timestamp when the change was made, foo.c will be older than
foo.p.
>
> 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
>
That may do the trick. But would it be easier to do just
# touch -F 10 foo
H.J.