Change file access and modification times (POSIX)
touch [-acm] [-r ref_file|-t time] file...
[[CC]YY]MMDDhhmm[.SS]
The two-digit pairs in time represent the following:
Both CC and YY are optional. If you specify neither of these, the current year is assumed. If you specify YY, but you don't specify CC, CC is derived as follows:
If YY is: | CC becomes: |
---|---|
69-99 | 19 |
00-68 | 20 |
The resulting time is affected by the value of the TZ environment variable (see below). If the resulting time precedes 0 hours, 0 minutes, 0 seconds, January 1, 1970 Coordinated Universal Time (i.e. the Epoch), touch exits immediately with an error status.
The range for SS is 00-61 rather than 00-59 to allow for leap seconds. If SS is 60 or 61, and the resulting time -- as affected by the TZ environment variable -- doesn't refer to a leap second, the resulting time is one second after a time where SS is 59. If you don't give a value to SS, it's assumed to be 0.
The touch utility lets you change either the modification times or access times of files, or both.
If any file you specify doesn't exist, the file is created unless you specify the -c option. If no time is specified, the current time is used. The -a option changes only the access time of the file; the -m option changes only the modification time of the file.
If you don't specify any options, touch behaves as if you used the -a and -m options.
Set file1's access and modification time to the current system time:
touch file1
Change file2's access and modification time to be the same as file1's modification time:
touch -r file1 file2
Set file3's access and modification time to December 25, 12:34, using the current year:
touch -t 12251234 file3