NAME
touch — change
file access and modification times
SYNOPSIS
touch |
[-acm] [-r
ref_file | -t
time] file
... |
Obsolescent |
Version: |
touch |
[-acm] [date_time]
file ... |
DESCRIPTION
The touch utility shall change the
modification and/or access times of files. The modification time is
equivalent to the value of the st_mtime member of the stat structure for a
file, as described in POSIX. 1 {8}; the access time is
equivalent to the value of st_atime. The time used can be specified by the
−t time option-argument, the corresponding time field(s) of the file
referenced by the −r ref_file option-argument, or the date_time
operand, as specified in the following subclauses. If none of these are
specified, touch shall use the current time [the
value returned by the equivalent of the POSIX. 1 {8}
time()
function]. For each file operand, touch shall
perform actions equivalent to the following functions defined in
POSIX. 1 {8}:
- If file does not exist, a
creat() function call is made with the file operand used as the path argument and the value of the bitwise inclusive OR of S_IRUSR, S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH, and S_IWOTH used as the mode argument. - The
utime() function is called with the following arguments: (a) The file operand is used as the path argument. (b) The utimbuf structure members actime and modtime are determined as described under OPTIONS .
OPTIONS
The touch utility shall conform to the
utility argument syntax guidelines described in 2.10.2. The following
options shall be supported by the implementation:
-a-
Change the access time of file. Do not change the modification time unless −m is also specified.
-c-
Do not create a specified file if it does not exist. Do not write any diagnostic messages concerning this condition.
-m-
Change the modification time of file. Do not change the access time unless −a is also specified.
-rref_file-
Use the corresponding time of the file named by the pathname ref_file instead of the current time.
-ttime-
Use the specified time instead of the current time. The optionargument shall be a decimal number of the form: [[CC]YY]MMDDhhmm[.SS] where each two digits represents the following: MM The month of the year (01-12). DD The day of the month (01-31). hh The hour of the day (00-23). mm The minute of the hour (00-59). CC The first two digits of the year (the century). YY The second two digits of the year. SS The second of the minute (00-61). Both CC and YY shall be optional. If neither is given, the current year shall be assumed. If YY is specified, but CC is not, CC shall be derived as follows:
If YY
is: CC
becomes: 69-99 19 00-68 20
The resulting time shall be affected by the value of the TZ environment variable. If the resulting time value precedes the Epoch,
touchshall exit immediately with an error status. The range of valid times past the Epoch is implementation defined, but shall extend to at least midnight 1 January 2000 UTC. The range for SS is (00-61) rather than (00-59) because of leap seconds. If SS is 60 or 61, and the resulting time, as affected by the TZ environment variable, does not refer to a leap second: the resulting time shall be one or two seconds after a time where SS is 59. If SS is not given a value, it is assumed to be zero. If neither the −a nor −m options were specified,touchshall behave as if both the -a-
and −m options were specified.
OPERANDS
The following operands shall be supported by the implementation:
- file
-
A pathname of a file whose times are to be modified.
- date_time
-
(Obsolescent.) Use the specified date_time instead of the current time. The operand is a decimal number of the form: MMDDhhmm[yy] where MM, DD, hh, and mm are as described for the time optionargument to the −t option and the optional yy is interpreted as follows: If not specified, the current year shall be used. If yy is in the range 69-99, the year 1969-1999, respectively, shall be used. Otherwise, the results are unspecified. If no −r option is specified, no −t option is specified, at least two operands are specified, and the first operand is an eight- or tendigit decimal integer, the first operand shall be assumed to be a date_time operand. Otherwise, the first operand shall be assumed to be a file operand.
STANDARD INPUT
None.
INPUT FILES
None.
ENVIRONMENT VARIABLES
The following environment variables shall affect the execution of
touch:
LANG-
This variable shall determine the locale to use for the locale categories when both LC_ALL and the corresponding environment variable (beginning with LC_ ) do not specify a locale. See 2.6.
LC_ALL-
This variable shall determine the locale to be used to override any values for locale categories specified by the settings of LANG or any environment variables beginning with LC_.
LC_CTYPE-
This variable shall determine the locale for the interpretation of sequences of bytes of text data as characters (e.g., single- versus multibyte characters in arguments).
LC_MESSAGES-
This variable shall determine the language in which messages should be written.
TZ-
If the time option-argument (or operand; see above) is specified, TZ shall be used to interpret the time for the specified time zone.
ASYNCHRONOUS EVENTS
Default.
STANDARD OUTPUT
None.
STANDARD ERROR
Used only for diagnostic messages.
OUTPUT FILES
None.
EXTENDED DESCRIPTION
None.
EXIT STATUS
The touch utility shall exit with one of
the following values:
CONSEQUENCES OF ERRORS
Default.
RATIONALE
EXAMPLES
The functionality of touch is described
almost entirely through references to functions in POSIX.
1 {8}. In this way, there is no duplication of effort required for
describing such side effects as the relationship of user IDs to the user
database, permissions, etc. The interpretation of time is taken to be
‘‘seconds since the Epoch,’’ as defined by
2.2.2.129. It should be noted that POSIX. 1 {8} conforming
implementations do not take leap seconds into account when computing seconds
since the Epoch. When SS=60 is used on POSIX. 1 {8}
conforming implementations, the resulting time always refers to 1 plus
‘‘seconds since the Epoch’’ for a time when
SS=59. Note that although the −t time option-argument and the
obsolescent date_time operand specify values in 1969, the access time and
modification time fields are defined in terms of seconds since the Epoch
(midnight on 1 January 1970 UTC ). Therefore, depending on
the value of TZ when touch is run, there will never
be more than a few valid hours in 1969 and there need not be any valid times
in 1969.
HISTORY OF DECISIONS MADE
There are some significant differences between this
touch and those in System V and
BSD systems. They are upward compatible for existing
applications from both implementations.
- In System V, an ambiguity exists when a pathname that is a decimal number leads the operands; it is treated as a time value. In BSD, no time value is allowed; files may only be touched to the current time. The [−t time] construct solves these problems for future portable applications (note that the −t option is not existing practice).
- The inclusion of the century digits, CC, is also new. Note that a ten-digit time value is treated as if YY, and not CC, were specified. The caveat about the range of dates following the Epoch was included as recognition that some UNIX systems will not be able to represent dates beyond the January 18, 2038, because they use signed int as a time holder.
One ambiguous situation occurs if −t time is not specified,
−r ref_file is not specified, and the first operand is an eight- or
ten-digit decimal number. A portable script can avoid this problem by using:
touch -- file or
touch ./file in this case. The −r
option was added because several comments requested this capability. This
option was named −f in an earlier draft, but was changed because the
−f option is used in the BSD version of
touch with a different meaning. At least one
historical implementation of touch incremented the
exit code if −c was specified and the file did not exist. This
standard requires exit status zero if no errors occur.