TOUCH(1) General Commands Manual TOUCH(1)

touchchange file access and modification times

touch [-acfhm] [-d datetime | -t timestamp | -r ref_file] file...

touch changes the date modification and access times on each file it is given.

Change the access time, no changes to modification time unless -m is also given.
Do not create file.
Ignored. coreutils and BusyBox never supported it, OpenBSD removed it in 2005, NetBSD in 2011, FreeBSD in 2012.
datetime
Use datetime instead of current time, see DATETIME FORMAT section for more details.
Do not follow symlinks.
Change the modification time, no changes to access time unless -a is also given.
timestamp
Use the specified timestamp instead of the current time, with the form [[CC]YY]MMDDhhmm[.SS] where:
CC
Corresponds to the first 2 digits of the year, aka %C
YY
Corresponds to the last 2 digits of the year, aka %y
MMDDhhmm
Corresponds to month, day, hours, minutes aka %m%d%H%M
.SS
Corresponds to the seconds

For example: ‘200306021337.42

ref_file
Use the corresponding times of the file at ref_file instead of the current time.

Multiple different but unambiguous formats are supported: @epoch, Email, asctime, RFC3339.

Leading @ (at) symbol followed by the Unix timestamp (number of seconds before and after 1970-01-01 00:00:00Z), for example ‘@1698791420’ corresponds to 2023-10-31 23:30:20 UTC

Also known as "Internet Message Format" (RFC5322, RFC2822, RFC822), for example:

  • Fri, 21 Nov 1997 09:55:06 -0600
  • 21 Nov 97 09:55:06 GMT

Output format of asctime(3), for example: ‘Sun Sep 16 01:03:52 1973

Profile of ISO 8601:1988, found in modern protocols and file formats. Formatted as ‘YYYY-MM-DDThh:mm:SS[frac][tz]’, where:

YYYY-MM-DD
Corresponds to %Y-%m-%d of strptime(3).
T
Is either ‘T’ or a space.
[frac]
Is either empty, or fractional seconds starting with either a comma (,) or a period (.).
[tz]
When empty it corresponds to local time. Otherwise it can be an UTC offset in the format ‘[+-]HH:?MM’ or the letter "Z", signifying UTC.

Some examples:

  • 2003-06-02T13:37:42.713Z
  • 1971-01-02T03:04:05.678+0900

The touch utility exits 0 on success, and >0 if an error occurs. Note: Will exit with failure when -c is given but the file doesn't exists.

stat(1), futimens(3), strptime(3)

touch should be compliant with the IEEE Std 1003.1-2024 (“POSIX.1”) specification.

-h and -f are extensions.

Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>

2023-06-03 Linux