TOUCH(1P)
๐ PROLOG ๐
okay so first things first, bestie โ this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux. so yeah, check your local vibes before you come for me ๐
โจ NAME โจ
touch โ change file access and modification times
ngl the name is doing the most with the least and I respect it ๐
๐ SYNOPSIS ๐
touch [-acm] [-r ref_file|-t time|-d date_time] file...
๐ธ DESCRIPTION ๐ธ
The touch utility shall change the last data modification timestamps, the last data access timestamps, or both. like it literally just nudges the clock on your files, iconic behavior โจ
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 -d date_time option-argument, as specified in the following sections. If none of these are specified, touch shall use the current time.
For each file operand, touch shall perform actions equivalent to the following functions defined in the System Interfaces volume of POSIX.1โ2017:
- If file does not exist:
- The
creat()function is called with the following arguments:- The file operand is used as the path argument.
- The value of the bitwise-inclusive OR of
S_IRUSR,S_IWUSR,S_IRGRP,S_IWGRP,S_IROTH, andS_IWOTHis used as the mode argument.
- The
futimens()function is called with the following arguments:- The file descriptor opened in step 1a.
- The access time and the modification time, set as described in the OPTIONS section, are used as the first and second elements of the times array argument, respectively.
- The
- If file exists, the
utimensat()function is called with the following arguments:- The
AT_FDCWDspecial value is used as the fd argument. - The file operand is used as the path argument.
- The access time and the modification time, set as described in the OPTIONS section, are used as the first and second elements of the times array argument, respectively.
- The flag argument is set to zero.
- The
so basically: no file โ make one, then set its times. file already there โ just set its times. periodt ๐
๐ OPTIONS ๐
The touch utility shall conform to the Base Definitions volume of POSIX.1โ2017, Section 12.2, Utility Syntax Guidelines.
The following options shall be supported:
-aโ Change the access time of file. Do not change the modification time unless-mis also specified. (access only, she's selective ๐ )-cโ Do not create a specified file if it does not exist. Do not write any diagnostic messages concerning this condition. like, no file, no drama, no notes ๐-ddate_time โ Use the specified date_time instead of the current time. The option-argument shall be a string of the form:
YYYY-MM-DDThh:mm:SS[.frac][tz]
or:
YYYY-MM-DDThh:mm:SS[,frac][tz]
where:
YYYYare at least four decimal digits giving the year.MM,DD,hh,mm, andSSare as with-ttime.Tis the time designator, and can be replaced by a single <space>.[.frac]and[,frac]are either empty, or a <period> (.) or a <comma> (,) respectively, followed by one or more decimal digits, specifying a fractional second.[tz]is either empty, signifying local time, or the letter'Z', signifying UTC. If[tz]is empty, the resulting time shall be affected by the value of theTZenvironment variable.
If the resulting time precedes the Epoch, the behavior is implementation-defined. If the time cannot be represented as the file's timestamp, touch shall exit immediately with an error status. no cap, it's just gonna dip ๐โโ๏ธ
-mโ Change the modification time of file. Do not change the access time unless-ais also specified. (modification only, she's also selective ๐)-rref_file โ Use the corresponding time of the file named by the pathname ref_file instead of the current time. stealing someone else's timestamp? lowkey iconic ๐-ttime โ Use the specified time instead of the current time. The option-argument 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,60].
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
YYis[69,99],CCbecomes19. - If
YYis[00,68],CCbecomes20.
Note: It is expected that in a future version of this standard the default century inferred from a 2-digit year will change. (This would apply to all commands accepting a 2-digit year as input.) so don't get too attached to the 1900s/2000s split, bestie ๐ซ
The resulting time shall be affected by the value of the TZ environment variable. If the resulting time value precedes the Epoch, the behavior is implementation-defined. If the time is out of range for the file's timestamp, touch shall exit immediately with an error status. The range of valid times past the Epoch is implementation-defined, but it shall extend to at least the time 0 hours, 0 minutes, 0 seconds, January 1, 2038, Coordinated Universal Time. Some implementations may not be able to represent dates beyond January 18, 2038, because they use signed int as a time holder.
The range for SS is [00,60] rather than [00,59] because of leap seconds. If SS is 60, and the resulting time, as affected by the TZ environment variable, does not refer to a leap second, the resulting time shall be one second 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 shall behave as if both the -a and -m options were specified. she does the whole thing by default, main character energy fr fr ๐
๐ OPERANDS ๐
The following operands shall be supported:
- file โ A pathname of a file whose times shall be modified.
๐ฆ STDIN ๐ฆ
Not used. she's not listening, she's just doing ๐
๐ INPUT FILES ๐
None.
๐ ENVIRONMENT VARIABLES ๐
The following environment variables shall affect the execution of touch:
LANGโ Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of POSIX.1โ2017, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.)LC_ALLโ If set to a non-empty string value, override the values of all the other internationalization variables. she overrides everybody, no apology ๐LC_CTYPEโ Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments).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 ofLC_MESSAGES.TZโ Determine the timezone to be used for interpreting the time option-argument. IfTZis unset or null, an unspecified default timezone shall be used.
๐ง ASYNCHRONOUS EVENTS ๐ง
Default.
โญ STDOUT โญ
Not used. silence, she's mysterious ๐
๐ STDERR ๐
The standard error shall be used only for diagnostic messages.
๐ธ OUTPUT FILES ๐ธ
None.
๐ EXTENDED DESCRIPTION ๐
None.
๐ EXIT STATUS ๐
The following exit values shall be returned:
0โ The utility executed successfully and all requested changes were made. ate and left no crumbs ๐ซถ>0โ An error occurred. ๐ญ
๐ซ CONSEQUENCES OF ERRORS ๐ซ
Default.
The following sections are informative. (yes bestie, everything from here down is the informative part, it's giving extra credit โจ)
๐ APPLICATION USAGE ๐
The interpretation of time is taken to be seconds since the Epoch (see the Base Definitions volume of POSIX.1โ2017, Section 4.16, Seconds Since the Epoch). It should be noted that implementations conforming to the System Interfaces volume of POSIX.1โ2017 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 specifies values in 1969, the access time and modification time fields are defined in terms of seconds since the Epoch (00:00:00 on 1 January 1970 UTC). Therefore, depending on the value of TZ when touch is run, there is never more than a few valid hours in 1969 and there need not be any valid times in 1969. so like, 1969 is barely there, blink and you'll miss it ๐
If the T time designator is replaced by a <space> for the -d date_time option-argument, the <space> must be quoted to prevent the shell from splitting the argument.
quote your spaces or the shell will absolutely split them apart, that's not a vibe, that's a bug you wrote yourself ๐
โจ EXAMPLES โจ
okay bestie, this is the part where we actually do the thing. buckle up. ๐
Let's make (or update) a file called dwc โ after this, both its last data modification AND last data access timestamps are set to November 12, 2007 at 10:15:30 local time:
touch -d 2007-11-12T10:15:30 dwc
Now same energy but for a file called nick, except the timestamps land on November 12, 2007 at 10:15:30 UTC:
touch -d 2007-11-12T10:15:30Z nick
Next up, gwc โ both the last data modification and last data access timestamps get set to November 12, 2007 at 10:15:30 local time, but with a fractional second timestamp of .002 seconds:
touch -d 2007-11-12T10:15:30,002 gwc
And ajosey? Both timestamps are November 12, 2007 at 10:15:30 UTC, again with that fractional second timestamp of .002 seconds:
touch -d "2007-11-12 10:15:30.002Z" ajosey
Meet cathy. Both her last data modification and last data access timestamps are November 12, 2007 at 10:15:00 local time โ no seconds this time, we're keeping it cute and rounded:
touch -t 200711121015 cathy
drepper over here gets both timestamps at November 12, 2007 at 10:15:30 local time:
touch -t 200711121015.30 drepper
ebb9 โ literally the same vibe, November 12, 2007 at 10:15:30 local time, just entered a different way:
touch -t 0711121015.30 ebb9
And finally eggert, who is the main character because instead of now, its last data access timestamp gets set to the corresponding time of the file named mark. And listen โ if the file already exists, the last data modification time is not changed. don't say I didn't warn you:
touch -a -r mark eggert
๐ RATIONALE ๐
so like, why is this page written this way?? The functionality of touch is described almost entirely through references to functions in the System Interfaces volume of POSIX.1โ2017. That way nobody has to duplicate effort describing side-effects like the relationship of user IDs to the user database, permissions, and so on. efficiency slay ๐
Now โ there are some significant differences between the touch utility in this volume of POSIX.1โ2017 and those in System V and BSD systems. They are upwards-compatible for historical applications from both implementations. periodt. here's the tea:
- 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
-ttime construct solves these problems for future conforming applications (note that the-toption is not historical practice). ๐ - The inclusion of the century digits,
CC, is also new. Note that a ten-digit time value is treated as ifYY, and notCC, were specified. The caveat about the range of dates following the Epoch was included as recognition that some implementations are not able to represent dates beyond 18 January 2038 because they use signedintas a time holder. yeah. 2038. scary fr ๐ญ
The -r option was added because several comments requested this capability. This option was named -f in an early proposal, but was changed because the -f option is used in the BSD version of touch with a different meaning. messy!! ๐
At least one historical implementation of touch incremented the exit code if -c was specified and the file did not exist. This volume of POSIX.1โ2017 requires exit status zero if no errors occur. we love a clean exit. โจ
In previous version of the standard, if at least two operands are specified, and the first operand is an eight or ten-digit decimal integer, the first operand was assumed to be a date_time operand. This usage was removed in this version of the standard since it had been marked obsolescent previously. it's gone bestie, rip. ๐
The -d date_time format is an ISO 8601:2004 standard complete representation of date and time extended format with an optional decimal point or <comma> followed by a string of digits following the seconds portion to specify fractions of a second. It is not necessary to recognize "[+/-]hh:mm" and "[+/-]hh" to specify timezones other than local time and UTC. The T time designator in the ISO 8601:2004 standard extended format may be replaced by <space>. iconic format tbh ๐ฆ
๐ฎ FUTURE DIRECTIONS ๐ฎ
None.
that's it. nothing. the future is a blank canvas, bestie. ๐
๐ SEE ALSO ๐
date
The Base Definitions volume of POSIX.1โ2017, Section 4.16, Seconds Since the Epoch, Chapter 8, Environment Variables, Section 12.2, Utility Syntax Guidelines, <sys_stat.h>
The System Interfaces volume of POSIX.1โ2017, creat(), futimens(), time(), utime()
๐ COPYRIGHT ๐
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's a wrap on touch bestie!! ๐ซถ this page comes to you courtesy of IEEE/The Open Group, dated 2017, and it lives under the name TOUCH(1P). go forth and set some timestamps, you absolute icon. ๐ธ๐โจ
๐ฆ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 ยท custom
- alpine 3.23: man-pages-posix 2017a-r0 ยท custom
- alpine 3.24: man-pages-posix 2017a-r0 ยท custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 ยท SUSE-IEEE
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms