1TOUCH(1P)                  POSIX Programmer's Manual                 TOUCH(1P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       touch — change file access and modification times
13

SYNOPSIS

15       touch [-acm] [-r ref_file|-t time|-d date_time] file...
16

DESCRIPTION

18       The touch utility shall change the last data  modification  timestamps,
19       the last data access timestamps, or both.
20
21       The time used can be specified by the -t time option-argument, the cor‐
22       responding time fields of  the  file  referenced  by  the  -r  ref_file
23       option-argument,  or  the -d date_time option-argument, as specified in
24       the following sections. If none of these are specified, touch shall use
25       the current time.
26
27       For  each  file  operand, touch shall perform actions equivalent to the
28       following  functions  defined  in  the  System  Interfaces  volume   of
29       POSIX.1‐2017:
30
31        1. If file does not exist:
32
33            a. The creat() function is called with the following arguments:
34
35               --  The file operand is used as the path argument.
36
37               --  The  value of the bitwise-inclusive OR of S_IRUSR, S_IWUSR,
38                   S_IRGRP, S_IWGRP, S_IROTH, and S_IWOTH is used as the  mode
39                   argument.
40
41            b. The futimens() function is called with the following arguments:
42
43               --  The file descriptor opened in step 1a.
44
45               --  The access time and the modification time, set as described
46                   in the OPTIONS section, are used as the  first  and  second
47                   elements of the times array argument, respectively.
48
49        2. If file exists, the utimensat() function is called with the follow‐
50           ing arguments:
51
52            a. The AT_FDCWD special value is used as the fd argument.
53
54            b. The file operand is used as the path argument.
55
56            c. The access time and the modification time, set as described  in
57               the  OPTIONS section, are used as the first and second elements
58               of the times array argument, respectively.
59
60            d. The flag argument is set to zero.
61

OPTIONS

63       The touch utility shall conform  to  the  Base  Definitions  volume  of
64       POSIX.1‐2017, Section 12.2, Utility Syntax Guidelines.
65
66       The following options shall be supported:
67
68       -a        Change  the access time of file.  Do not change the modifica‐
69                 tion time unless -m is also specified.
70
71       -c        Do not create a specified file if it does not exist.  Do  not
72                 write any diagnostic messages concerning this condition.
73
74       -d date_time
75                 Use  the specified date_time instead of the current time. The
76                 option-argument shall be a string of the form:
77
78
79                     YYYY-MM-DDThh:mm:SS[.frac][tz]
80
81                 or:
82
83
84                     YYYY-MM-DDThh:mm:SS[,frac][tz]
85
86                 where:
87
88                  *  YYYY are at least four decimal digits giving the year.
89
90                  *  MM, DD, hh, mm, and SS are as with -t time.
91
92                  *  T is the time designator, and can be replaced by a single
93                     <space>.
94
95                  *  [.frac] and [,frac] are either empty, or a <period> ('.')
96                     or a <comma> (',') respectively, followed by one or  more
97                     decimal digits, specifying a fractional second.
98
99                  *  [tz]  is either empty, signifying local time, or the let‐
100                     ter 'Z', signifying UTC. If [tz] is empty, the  resulting
101                     time shall be affected by the value of the TZ environment
102                     variable.
103
104                 If the resulting time precedes the  Epoch,  the  behavior  is
105                 implementation-defined.  If the time cannot be represented as
106                 the file's timestamp, touch shall exit  immediately  with  an
107                 error status.
108
109       -m        Change  the  modification  time  of  file.  Do not change the
110                 access time unless -a is also specified.
111
112       -r ref_file
113                 Use the corresponding time of the file named by the  pathname
114                 ref_file instead of the current time.
115
116       -t time   Use  the  specified  time  instead  of  the current time. The
117                 option-argument shall be a decimal number of the form:
118
119
120                     [[CC]YY]MMDDhhmm[.SS]
121
122                 where each two digits represents the following:
123
124                 MM      The month of the year [01,12].
125
126                 DD      The day of the month [01,31].
127
128                 hh      The hour of the day [00,23].
129
130                 mm      The minute of the hour [00,59].
131
132                 CC      The first two digits of the year (the century).
133
134                 YY      The second two digits of the year.
135
136                 SS      The second of the minute [00,60].
137
138                 Both CC and YY shall be optional. If neither  is  given,  the
139                 current  year shall be assumed. If YY is specified, but CC is
140                 not, CC shall be derived as follows:
141
142                                   ┌──────────┬─────────────┐
143If YY is: CC becomes: 
144                                   ├──────────┼─────────────┤
145                                   │ [69,99]  │     19      │
146                                   │ [00,68]  │     20      │
147                                   └──────────┴─────────────┘
148                 Note:     It is expected that in a  future  version  of  this
149                           standard   the  default  century  inferred  from  a
150                           2-digit year will change. (This would apply to  all
151                           commands accepting a 2-digit year as input.)
152
153                 The  resulting  time shall be affected by the value of the TZ
154                 environment variable. If the resulting  time  value  precedes
155                 the  Epoch,  the  behavior  is implementation-defined. If the
156                 time is out of range for the file's  timestamp,  touch  shall
157                 exit  immediately  with  an  error status. The range of valid
158                 times past the Epoch is implementation-defined, but it  shall
159                 extend  to  at  least the time 0 hours, 0 minutes, 0 seconds,
160                 January 1, 2038, Coordinated Universal Time. Some implementa‐
161                 tions  may  not be able to represent dates beyond January 18,
162                 2038, because they use signed int as a time holder.
163
164                 The range for SS is [00,60] rather than  [00,59]  because  of
165                 leap  seconds.  If  SS  is  60,  and  the  resulting time, as
166                 affected by the TZ environment variable, does not refer to  a
167                 leap  second,  the resulting time shall be one second after a
168                 time where SS is 59. If SS  is  not  given  a  value,  it  is
169                 assumed to be zero.
170
171       If  neither the -a nor -m options were specified, touch shall behave as
172       if both the -a and -m options were specified.
173

OPERANDS

175       The following operands shall be supported:
176
177       file      A pathname of a file whose times shall be modified.
178

STDIN

180       Not used.
181

INPUT FILES

183       None.
184

ENVIRONMENT VARIABLES

186       The following environment  variables  shall  affect  the  execution  of
187       touch:
188
189       LANG      Provide  a  default  value for the internationalization vari‐
190                 ables that are unset or null. (See the Base Definitions  vol‐
191                 ume  of POSIX.1‐2017, Section 8.2, Internationalization Vari‐
192                 ables for the precedence  of  internationalization  variables
193                 used to determine the values of locale categories.)
194
195       LC_ALL    If  set  to  a non-empty string value, override the values of
196                 all the other internationalization variables.
197
198       LC_CTYPE  Determine the locale for the interpretation of  sequences  of
199                 bytes of text data as characters (for example, single-byte as
200                 opposed to multi-byte characters in arguments).
201
202       LC_MESSAGES
203                 Determine the locale that should be used to affect the format
204                 and  contents  of  diagnostic  messages  written  to standard
205                 error.
206
207       NLSPATH   Determine the location of message catalogs for the processing
208                 of LC_MESSAGES.
209
210       TZ        Determine  the  timezone to be used for interpreting the time
211                 option-argument. If TZ  is  unset  or  null,  an  unspecified
212                 default timezone shall be used.
213

ASYNCHRONOUS EVENTS

215       Default.
216

STDOUT

218       Not used.
219

STDERR

221       The standard error shall be used only for diagnostic messages.
222

OUTPUT FILES

224       None.
225

EXTENDED DESCRIPTION

227       None.
228

EXIT STATUS

230       The following exit values shall be returned:
231
232        0    The  utility executed successfully and all requested changes were
233             made.
234
235       >0    An error occurred.
236

CONSEQUENCES OF ERRORS

238       Default.
239
240       The following sections are informative.
241

APPLICATION USAGE

243       The interpretation of time is taken to be seconds since the Epoch  (see
244       the  Base  Definitions  volume  of  POSIX.1‐2017, Section 4.16, Seconds
245       Since the Epoch).  It should be noted that  implementations  conforming
246       to  the  System Interfaces volume of POSIX.1‐2017 do not take leap sec‐
247       onds into account when computing seconds since the Epoch. When SS=60 is
248       used,  the  resulting  time  always  refers to 1 plus seconds since the
249       Epoch for a time when SS=59.
250
251       Although the -t time option-argument  specifies  values  in  1969,  the
252       access  time  and modification time fields are defined in terms of sec‐
253       onds since the Epoch (00:00:00  on  1  January  1970  UTC).  Therefore,
254       depending  on  the  value  of TZ when touch is run, there is never more
255       than a few valid hours in 1969 and there need not be any valid times in
256       1969.
257
258       If  the T time designator is replaced by a <space> for the -d date_time
259       option-argument, the <space> must be quoted to prevent the  shell  from
260       splitting the argument.
261

EXAMPLES

263       Create  or  update  a  file called dwc; the resulting file has both the
264       last data modification and last data access timestamps set to  November
265       12, 2007 at 10:15:30 local time:
266
267
268           touch -d 2007-11-12T10:15:30 dwc
269
270       Create  or  update  a file called nick; the resulting file has both the
271       last data modification and last data access timestamps set to  November
272       12, 2007 at 10:15:30 UTC:
273
274
275           touch -d 2007-11-12T10:15:30Z nick
276
277       Create  or  update  a  file called gwc; the resulting file has both the
278       last data modification and last data access timestamps set to  November
279       12,  2007  at 10:15:30 local time with a fractional second timestamp of
280       .002 seconds:
281
282
283           touch -d 2007-11-12T10:15:30,002 gwc
284
285       Create or update a file called ajosey; the resulting file has both  the
286       last  data modification and last data access timestamps set to November
287       12, 2007 at 10:15:30 UTC with a fractional  second  timestamp  of  .002
288       seconds:
289
290
291           touch -d "2007-11-12 10:15:30.002Z" ajosey
292
293       Create  or  update a file called cathy; the resulting file has both the
294       last data modification and last data access timestamps set to  November
295       12, 2007 at 10:15:00 local time:
296
297
298           touch -t 200711121015 cathy
299
300       Create or update a file called drepper; the resulting file has both the
301       last data modification and last data access timestamps set to  November
302       12, 2007 at 10:15:30 local time:
303
304
305           touch -t 200711121015.30 drepper
306
307       Create  or  update  a file called ebb9; the resulting file has both the
308       last data modification and last data access timestamps set to  November
309       12, 2007 at 10:15:30 local time:
310
311
312           touch -t 0711121015.30 ebb9
313
314       Create  or update a file called eggert; the resulting file has the last
315       data access timestamp set to the corresponding time of the  file  named
316       mark  instead  of  the  current time. If the file exists, the last data
317       modification time is not changed:
318
319
320           touch -a -r mark eggert
321

RATIONALE

323       The functionality of touch is described almost entirely through  refer‐
324       ences  to functions in the System Interfaces volume of POSIX.1‐2017. In
325       this way, there is no duplication of  effort  required  for  describing
326       such side-effects as the relationship of user IDs to the user database,
327       permissions, and so on.
328
329       There are some significant differences between  the  touch  utility  in
330       this volume of POSIX.1‐2017 and those in System V and BSD systems. They
331       are upwards-compatible for historical applications from both  implemen‐
332       tations:
333
334        1. In  System V, an ambiguity exists when a pathname that is a decimal
335           number leads the operands; it is treated as a time value.  In  BSD,
336           no  time value is allowed; files may only be touched to the current
337           time. The -t time construct solves these problems for  future  con‐
338           forming  applications  (note  that  the -t option is not historical
339           practice).
340
341        2. The inclusion of the century digits, CC, is also new. Note  that  a
342           ten-digit  time  value is treated as if YY, and not CC, were speci‐
343           fied. The caveat about the range of dates following the  Epoch  was
344           included  as  recognition that some implementations are not able to
345           represent dates beyond 18 January 2038 because they use signed  int
346           as a time holder.
347
348       The  -r  option was added because several comments requested this capa‐
349       bility.  This option was named -f in an early proposal, but was changed
350       because  the  -f option is used in the BSD version of touch with a dif‐
351       ferent meaning.
352
353       At least one historical implementation of touch  incremented  the  exit
354       code  if  -c  was  specified and the file did not exist. This volume of
355       POSIX.1‐2017 requires exit status zero if no errors occur.
356
357       In previous version of the standard, if at least two operands are spec‐
358       ified,  and the first operand is an eight or ten-digit decimal integer,
359       the first operand was assumed to be a date_time operand. This usage was
360       removed  in this version of the standard since it had been marked obso‐
361       lescent previously.
362
363       The -d date_time format is an ISO 8601:2004 standard complete represen‐
364       tation  of date and time extended format with an optional decimal point
365       or <comma> followed by a string of digits following the seconds portion
366       to  specify  fractions  of  a  second. It is not necessary to recognize
367       "[+/-]hh:mm" and "[+/-]hh" to specify timezones other than  local  time
368       and  UTC.  The T time designator in the ISO 8601:2004 standard extended
369       format may be replaced by <space>.
370

FUTURE DIRECTIONS

372       None.
373

SEE ALSO

375       date
376
377       The Base Definitions volume  of  POSIX.1‐2017,  Section  4.16,  Seconds
378       Since  the Epoch, Chapter 8, Environment Variables, Section 12.2, Util‐
379       ity Syntax Guidelines, <sys_stat.h>
380
381       The System Interfaces  volume  of  POSIX.1‐2017,  creat(),  futimens(),
382       time(), utime()
383
385       Portions  of  this text are reprinted and reproduced in electronic form
386       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
387       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
388       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
389       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
390       event of any discrepancy between this version and the original IEEE and
391       The  Open Group Standard, the original IEEE and The Open Group Standard
392       is the referee document. The original Standard can be  obtained  online
393       at http://www.opengroup.org/unix/online.html .
394
395       Any  typographical  or  formatting  errors that appear in this page are
396       most likely to have been introduced during the conversion of the source
397       files  to  man page format. To report such errors, see https://www.ker
398       nel.org/doc/man-pages/reporting_bugs.html .
399
400
401
402IEEE/The Open Group                  2017                            TOUCH(1P)
Impressum