bug-coreutils
[Top][All Lists]
Advanced

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

Re: a bug in "touch"?


From: Steve Magee
Subject: Re: a bug in "touch"?
Date: Thu, 29 Jan 2004 15:09:58 -0800

Bob - Thank you very much for your reply.

Sorry about not supplying you with the version of "touch".
Just assume that with RH v9, the version of touch was known.

Your suggestion of using ls -l --time-style=long-iso does work 
correctly in my script.  By the way, more options for --time-style
are found in "info" then in "man".  Coming from UNIX, I keep 
forgetting to use the "info" command.  

I feel this concern of using the current year should be noted in 
the manpage of touch. It is noted regarding the date input format 
in the "info touch".

I was already using your method of using a temporary filename
to make the changes.  The problem was just the small window
after the turn of the new year.  When I tested this out, it
was in the middle of the year.  It worked, so I applied the
method that worked.  6 months after the last update to that file, 
the time changes to the year of last update.  My old method of 
touch -d "$mo $day $yrtime" fn, did not change the timestamp that 
had the year, instead of the time.

Again, thank you very much for your help.  I'll try and 
refer to "info" more often.  Hate to see the manpage disappear.
It's part of UNIX like the who command.

Thanks
Steve Magee


Bob Proulx wrote:
> 
> Steve Magee wrote:
> > I'm running RH v9 and using the touch command
> > to keep the same date and time on files after a sort.
> 
> Thanks for taking the time to report a problem.  But when reporting
> problems please say what version of the program you are using.  There
> are many software distributions and it is impossible to keep up with
> them all.  Frequently it is found that the program isn't even one of
> the ones maintained here!
> 
>   date --version
> 
> > My method used is:
> >
> > touch -d "$mon $day $yrtime" filename
> >
> > [...]
> > When issuing the command above and in the
> > format above, it sets the timestamp a year ahead.
> >
> > Example: In January, you issue the command above
> > where $mon = Dec, $day = 31 and $yrtime = 12:30.
> > These parameter are taken from the ls -la | awk command.
> 
>   touch -d "Dec 31 12:30" filename
> 
> The -d option parses a date string.  The date string is missing a year
> and so the current year is assumed.  That is correct.  You can use the
> 'date' command to parse the string and report a full time output this
> way in the current locale.
> 
>   date -d "Dec 31 12:30"
>   Fri Dec 31 12:30:00 MST 2004
> 
> Therefore touch is doing exactly as it is instructed to do.
> 
> > The file...
> > -rwx------    1 major    daemon       2173 Dec 31 12:30 x
> > becomes...
> > -rwx------    1 major    daemon       2173 Dec 31  2004 x
> > I believe this is a bug in the touch command.
> 
> I think you are missing how the 'ls' long listing format is
> constructed.  It changes format depending upon the date.  Here is the
> documentation on it.
> 
>   info ls
>   info '(coreutils)What information is listed'
> 
>   `-l'
>   `--format=long'
>   `--format=verbose'
>        In addition to the name of each file, print the file type,
>        permissions, number of hard links, owner name, group name, size in
>        bytes, and timestamp (by default, the modification time).  For
>        files with a time more than six months old or in the future, the
>        timestamp contains the year instead of the time of day.  If the
>        timestamp contains today's date with the year rather than a time
>        of day, the file's time is in the future, which means you probably
>        have clock skew problems which may break programs like `make' that
>        rely on file times.
> 
> Therefore ls is reporting the date in a format which has a moving
> window of time around the current time.  This difference in format is
> confusing your script.  It would be better to use a different time
> format such as the --time-style format which can produce an
> unambiguous time string.
> 
> You did not say which version of date you were using so I cannot say
> if this feature is available in your version.  But I think
> 'ls -l --time-style=long-iso' is probably a reasonable format for your
> use.
> 
> Since you said you were restoring the timestamp on the file after a
> sort I suggest doing this differently.  Sort to a temporary file and
> then set the timestamp on that file based on the previous file.
> Perhaps something similar to this following script-let.  This is off
> the top of my head and completely untested so you will have to work
> out the final details yourself.  This eliminates the problems of
> parsing what is meant to be human readable output from ls.
> 
>   #!/bin/sh
>   trap 'rm -f $TMPFILE' 0
>   TMPFILE=`mktemp -p .`
>   sort myfile > $TMPFILE
>   chmod --reference myfile $TMPFILE
>   touch --reference myfile $TMPFILE
>   mv --force $TMPFILE myfile
> 
> Bob




reply via email to

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