GNU bug report logs -
#7999
[coreutils-8.x] documentation of touch command needs clarification
Previous Next
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your message dated Mon, 12 Dec 2011 16:59:39 -0800
with message-id <4EE6A37B.40407 <at> cs.ucla.edu>
and subject line Re: bug#7999: [coreutils-8.x] documentation of touch command needs clarification
has caused the debbugs.gnu.org bug report #7999,
regarding [coreutils-8.x] documentation of touch command needs clarification
to be marked as done.
(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)
--
7999: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=7999
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
Examination of the info documention for the coreutils-8.x
implementation of the touch command, and the POSIX (IEEE Std
1003.1-2001), does not make clear exactly what time is used when the
argument files exist, and no time specifier (-r or -t option) is
supplied.
For example,
touch first second .... umpteenth
If the files do not exist, then POSIX says
35294 1. If file does not exist, a creat( ) function call is made with the file operand used as the path
35295 argument and the value of the bitwise-inclusive OR of S_IRUSR, S_IWUSR, S_IRGRP,
35296 S_IWGRP, S_IROTH, and S_IWOTH used as the mode argument.
That implies that each newly-created file gets the time of its
creation, so the timestamps should be expected to differ if the clock
resolution is not too coarse.
However, if the files already exist, what happens? Should the files
all get the same timestamp, or the timestamp in effect when the touch
of that file actually occurred?
If I want to guarantee identical timestamps, am I forced to use a
temporary reference file, perhaps like this?
touch /tmp/TIMESTAMP.$$
touch -r /tmp/TIMESTAMP.$$ first second ... umpteenth
rm -f /tmp/TIMESTAMP.$$
Perhaps the coreutils manual page and info documentation could be
updated to document what that implementation does, and discuss whether
it agrees or differs from other implementations (and POSIX).
Because file timestamps are used heavily by commands like "make" and
"rsync", it can be important to know how the touch command does its
job.
An experiment on SGI IRIX (a system with microsecond-resolution
timestamps) with coreutils-7.5 shows that the touch command from that
release has a new time for each file:
% /usr/local/bin/touch /tmp/fee.{`seq -s , 1000 2000`}
% /usr/local/bin/touch /tmp/fee.{`seq -s , 1000 2000`}
% stat /tmp/fee.?000
File: `/tmp/fee.1000'
...
Access: 2011-02-07 16:27:07.332753000 -0700
...
File: `/tmp/fee.2000'
...
Access: 2011-02-07 16:27:09.934987800 -0700
Similar behavior is found with coreutils-8.9 on NetBSD IA-32 and Sun
Solaris SPARC.
-------------------------------------------------------------------------------
- Nelson H. F. Beebe Tel: +1 801 581 5254 -
- University of Utah FAX: +1 801 581 4148 -
- Department of Mathematics, 110 LCB Internet e-mail: beebe <at> math.utah.edu -
- 155 S 1400 E RM 233 beebe <at> acm.org beebe <at> computer.org -
- Salt Lake City, UT 84112-0090, USA URL: http://www.math.utah.edu/~beebe/ -
-------------------------------------------------------------------------------
[Message part 3 (message/rfc822, inline)]
I installed the following patch to try to document this issue better
and am taking the liberty of marking this as done. Further comments
are welcome (and we can reopen the bug as needed).
doc: document 'touch' and timestamps better
* doc/coreutils.texi (touch invocation): Explain file timestamps
better. Problem reported by Nelson H.F. Beebe (Bug#7999).
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 369fad2..c26a53d 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -7199,6 +7199,7 @@ a date like @samp{Mar 30@ @ 2002} for non-recent timestamps, and a
date-without-year and time like @samp{Mar 30 23:45} for recent timestamps.
This format can change depending on the current locale as detailed below.
+@cindex clock skew
A timestamp is considered to be @dfn{recent} if it is less than six
months old, and is not dated in the future. If a timestamp dated
today is not listed in recent form, the timestamp is in the future,
@@ -10261,11 +10262,39 @@ A @var{file} argument string of @samp{-} is handled specially and
causes @command{touch} to change the times of the file associated with
standard output.
+@cindex clock skew
+By default, @command{touch} sets file timestamps to the current time.
+Because @command{touch} acts on its operands left to right, the
+resulting timestamps of earlier and later operands may disagree.
+Also, the determination of what time is ``current'' depends on the
+platform. Platforms with network file systems often use different
+clocks for the operating system and for file systems; because
+@command{touch} typically uses file systems' clocks by default, clock
+skew can cause the resulting file timestamps to appear to be in a
+program's ``future'' or ``past''.
+
+@cindex file timestamp resolution
+The @command{touch} command sets the file's timestamp to the greatest
+representable value that is not greater than the requested time. This
+can differ from the requested time for several reasons. First, the
+requested time may have a higher resolution than supported. Second, a
+file system may use different resolutions for different types of
+times. Third, file timestamps may use a different resolution than
+operating system timestamps. Fourth, the operating system primitives
+used to update timestamps may employ yet a different resolution. For
+example, in theory a file system might use 10-microsecond resolution
+for access time and 100-nanosecond resolution for modification time,
+and the operating system might use nanosecond resolution for the
+current time and microsecond resolution for the primitive that
+@command{touch} uses to set a file's timestamp to an arbitrary value.
+
@cindex permissions, for changing file timestamps
-If changing both the access and modification times to the current
-time, @command{touch} can change the timestamps for files that the user
-running it does not own but has write permission for. Otherwise, the
-user must own the files.
+When setting file timestamps to the current time, @command{touch} can
+change the timestamps for files that the user does not own but has
+write permission for. Otherwise, the user must own the files. Some
+older systems have a further restriction: the user must own the files
+unless both the access and modification times are being set to the
+current time.
Although @command{touch} provides options for changing two of the times---the
times of last access and modification---of a file, there is actually
This bug report was last modified 13 years and 161 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.