touch is used to set the access and modification times of files to the current or specified date.
Syntax
Format 1: | touch[ -acm][-r ref_file | -t time] file ... |
Format 2: | touch[ -acm][ MMDDhhmm[yy]] file ... |
No option specified touch sets the last modification and access times for the specified files to the specified or current date. If a file does not yet exist then touch creates it. touch without an option therefore has the same effect as touch -am.
(access time) touch sets the the last access time for the specified files to the specified or current date. If neither -a nor -m is specified:
touch does not create files which do not exist. In such a case, no message is output.
(modification time) touch sets the last modification time for the specified files to the specified or current date. Neither -a nor -m specified:
Instead of the current time, touch uses the corresponding date and time from ref_file.
Instead of the current time, touch uses the time specified in time. time is output as a decimal number with the following format:
The first two figures of the year specification (century). The century specification is optional. If you do not specify a century, the current century is used.
The last two figures of the year specification (decade and year). The decade and year specification is optional. If no decade and year are specified, the current decade and year are used. If the decade and year are specified but the century CC is not, then CC is calculated as follows: for 69
Month (01-12)
Day (01-31)
Hours (00-23)
Minutes (00-59)
Seconds (00-61). The seconds specification is optional. If you do not specify SS then the value 00 is used. If you wish to specify the seconds, the value of SS must be in the range 00-61 (instead of the usual range 00-59). The values 60 and 61 should be considered as reserve seconds. The highest date you can specify for time is:
file Name of the input file. touch processes all types of files, including directories. Several file names may be specified in one call. |
No option specified touch sets the access and modification times of the named files to the specified or current date. If a file does not exist, it is created. Calling touch without options is thus equivalent to touch -am.
(access time) updates only the access time of the named files to the specified or current date. If neither -a nor -m is specified:
Prevents touch from creating a file if the named file did not previously exist. No corresponding message is issued.
(modification time) Updates only the modification time of the named files to the specified or current date. If neither -a nor -m is specified:
Date and time to which the access and/or modification times of the specified files are to be set. The date/time argument comprises eight to ten digits with the following significance: If you specify the year YY but not the millennium CC, CC is inferred as follows: with 69 The highest date you can specify for time is:
YY not specified: MMDDhhmm[YY] not specified:
Name of the input file. touch processes all types of files, including directories. Several file names may be specified in one call. |
Error
You have specified an illegal date, e.g. 13010000. |
Variable
TZ Determine the timezone to be used for interpreting the time option argument. |
Locale
The following environment variables affect the execution of touch: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE 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 and input files), the classification of characters as upper- to lower-case, and the mapping of characters from one case to the other. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. |
Example 1
Set the access and modification times of file to the current date. No new file is to be created if this file does not exist.
The ls -l command can be used to display the time of the last modification; ls -lu outputs the access time. |
Example 2
Set the access time of file to 9 o’clock on 8/26:
|
See also
date, ls |