The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group


touch - change file access and modification times


touch [-acm][ -r ref_file| -t time] file...

touch [-acm][date_time] file...


The touch utility will change the modification times, access times or both 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 the XSH specification; 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 fields of the file referenced by the -r ref_file option-argument, or the date_time operand, as specified in the following sections. If none of these are specified, touch will use the current time (the value returned by the equivalent of the XSH specification time() function).

For each file operand, touch will perform actions equivalent to the following functions defined in the XSH specification:

  1. 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.

  2. The utime() function is called with the following arguments:

    1. The file operand is used as the path argument.

    2. The utimbuf structure members actime and modtime are determined as described in the OPTIONS section.


The touch utility supports the XBD specification, Utility Syntax Guidelines  .

The following options are supported:

Change the access time of file. Do not change the modification time unless -m is also specified.
Do not create a specified file if it does not exist. Do not write any diagnostic messages concerning this condition.
Change the modification time of file. Do not change the access time unless -a is also specified.
-r ref_file
Use the corresponding time of the file named by the pathname ref_file instead of the current time.
-t time
Use the specified time instead of the current time. The option-argument will be a decimal number of the form:


where each two digits represents the following:
The month of the year [01-12].
The day of the month [01-31].
The hour of the day [00-23].
The minute of the hour [00-59].
The first two digits of the year (the century).
The second two digits of the year.
The second of the minute [00-61].

Both CC and YY are optional. If neither is given, the current year will be assumed. If YY is specified, but CC is not, CC will be derived as follows:

If YY is: CC becomes:
69-99 19
00-68 20

The resulting time will be affected by the value of the TZ environment variable. If the resulting time value precedes the Epoch, touch will exit immediately with an error status. The range of valid times past the Epoch is implementation-dependent, but will extend to at least the time 0 hours, 0 minutes, 0 seconds, January 1, 2038, Coordinated Universal Time. Some systems will not be able to represent dates beyond the January 18, 2038, because they use signed int as a time holder.

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 will 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, touch will behave as if both the -a and -m options were specified.


The following operands are supported:
A pathname of a file whose times are to be modified.
Use the specified date_time instead of the current time. The operand is a decimal number of the form:


where MM, DD, hh, and mm are as described for the time option-argument to the -t option and the optional yy is interpreted as follows:
If not specified, the current year will be used. If yy is in the range 69-99, the year 1969-1999, respectively, will 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 ten-digit decimal integer, the first operand will be assumed to be a date_time operand. Otherwise, the first operand will be assumed to be a file operand.


Not used.




The following environment variables affect the execution of touch:
Provide a default value for the internationalisation variables that are unset or null. If LANG is unset or null, the corresponding value from the implementation-dependent default locale will be used. If any of the internationalisation variables contains an invalid setting, the utility will behave as if none of the variables had been defined.
If set to a non-empty string value, override the values of all the other internationalisation variables.
Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments).
Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
Determine the location of message catalogues for the processing of LC_MESSAGES .
Determine the timezone to be used for interpreting the time option-argument (or date_time operand; see above).




Not used.


Used only for diagnostic messages.






The following exit values are returned:
The utility executed successfully and all requested changes were made.
An error occurred.




The interpretation of time is taken to be seconds since the Epoch (see the XBD specification, Glossary  ). It should be noted that implementations conforming to the XSH specification do not take leap seconds into account when computing seconds since the Epoch. When SS=60 is used, the resulting time always refers to 1 plus "seconds since the Epoch" for a time when SS=59.

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.

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


touch ./file

in this case.




The obsolescent date_time operand may be withdrawn in a future issue. Applications should use the -r or -t options.


date, the XSH specification description of creat(), time(), <sys/stat.h>.

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]