1TOUCH(P) POSIX Programmer's Manual TOUCH(P)
2
3
4
6 touch - change file access and modification times
7
9 touch [-acm][ -r ref_file| -t time] file...
10
12 The touch utility shall change the modification times, access times, or
13 both of files. The modification time shall be equivalent to the value
14 of the st_mtime member of the stat structure for a file, as described
15 in the System Interfaces volume of IEEE Std 1003.1-2001; the access
16 time shall be equivalent to the value of st_atime.
17
18 The time used can be specified by the -t time option-argument, the cor‐
19 responding time fields of the file referenced by the -r ref_file
20 option-argument, or the date_time operand, as specified in the follow‐
21 ing sections. If none of these are specified, touch shall use the cur‐
22 rent time (the value returned by the equivalent of the time() function
23 defined in the System Interfaces volume of IEEE Std 1003.1-2001).
24
25 For each file operand, touch shall perform actions equivalent to the
26 following functions defined in the System Interfaces volume of
27 IEEE Std 1003.1-2001:
28
29 1. If file does not exist, a creat() function call is made with the
30 file operand used as the path argument and the value of the bit‐
31 wise-inclusive OR of S_IRUSR, S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH,
32 and S_IWOTH used as the mode argument.
33
34 2. The utime() function is called with the following arguments:
35
36 a. The file operand is used as the path argument.
37
38 b. The utimbuf structure members actime and modtime are determined
39 as described in the OPTIONS section.
40
42 The touch utility shall conform to the Base Definitions volume of
43 IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
44
45 The following options shall be supported:
46
47 -a Change the access time of file. Do not change the modification
48 time unless -m is also specified.
49
50 -c Do not create a specified file if it does not exist. Do not
51 write any diagnostic messages concerning this condition.
52
53 -m Change the modification time of file. Do not change the access
54 time unless -a is also specified.
55
56 -r ref_file
57 Use the corresponding time of the file named by the pathname
58 ref_file instead of the current time.
59
60 -t time
61 Use the specified time instead of the current time. The option-
62 argument shall be a decimal number of the form:
63
64
65 [[CC]YY]MMDDhhmm[.SS]
66
67 where each two digits represents the following:
68
69 MM
70 The month of the year [01,12].
71
72 DD
73 The day of the month [01,31].
74
75 hh
76 The hour of the day [00,23].
77
78 mm
79 The minute of the hour [00,59].
80
81 CC
82 The first two digits of the year (the century).
83
84 YY
85 The second two digits of the year.
86
87 SS
88 The second of the minute [00,60].
89
90
91 Both CC and YY shall be optional. If neither is given, the current year
92 shall be assumed. If YY is specified, but CC is not, CC shall be
93 derived as follows:
94
95 If YY is: CC becomes:
96 [69,99] 19
97 [00,68] 20
98
99 Note:
100 It is expected that in a future version of IEEE Std 1003.1-2001
101 the default century inferred from a 2-digit year will change.
102 (This would apply to all commands accepting a 2-digit year as
103 input.)
104
105
106 The resulting time shall be affected by the value of the TZ environment
107 variable. If the resulting time value precedes the Epoch, touch shall
108 exit immediately with an error status. The range of valid times past
109 the Epoch is implementation-defined, but it shall extend to at least
110 the time 0 hours, 0 minutes, 0 seconds, January 1, 2038, Coordinated
111 Universal Time. Some implementations may not be able to represent dates
112 beyond January 18, 2038, because they use signed int as a time holder.
113
114 The range for SS is [00,60] rather than [00,59] because of leap sec‐
115 onds. If SS is 60, and the resulting time, as affected by the TZ envi‐
116 ronment variable, does not refer to a leap second, the resulting time
117 shall be one second after a time where SS is 59. If SS is not given a
118 value, it is assumed to be zero.
119
120
121 If neither the -a nor -m options were specified, touch shall behave as
122 if both the -a and -m options were specified.
123
125 The following operands shall be supported:
126
127 file A pathname of a file whose times shall be modified.
128
129
131 Not used.
132
134 None.
135
137 The following environment variables shall affect the execution of
138 touch:
139
140 LANG Provide a default value for the internationalization variables
141 that are unset or null. (See the Base Definitions volume of
142 IEEE Std 1003.1-2001, Section 8.2, Internationalization Vari‐
143 ables for the precedence of internationalization variables used
144 to determine the values of locale categories.)
145
146 LC_ALL If set to a non-empty string value, override the values of all
147 the other internationalization variables.
148
149 LC_CTYPE
150 Determine the locale for the interpretation of sequences of
151 bytes of text data as characters (for example, single-byte as
152 opposed to multi-byte characters in arguments).
153
154 LC_MESSAGES
155 Determine the locale that should be used to affect the format
156 and contents of diagnostic messages written to standard error.
157
158 NLSPATH
159 Determine the location of message catalogs for the processing of
160 LC_MESSAGES .
161
162 TZ Determine the timezone to be used for interpreting the time
163 option-argument. If TZ is unset or null, an unspecified default
164 timezone shall be used.
165
166
168 Default.
169
171 Not used.
172
174 The standard error shall be used only for diagnostic messages.
175
177 None.
178
180 None.
181
183 The following exit values shall be returned:
184
185 0 The utility executed successfully and all requested changes were
186 made.
187
188 >0 An error occurred.
189
190
192 Default.
193
194 The following sections are informative.
195
197 The interpretation of time is taken to be seconds since the Epoch (see
198 the Base Definitions volume of IEEE Std 1003.1-2001, Section 4.14, Sec‐
199 onds Since the Epoch). It should be noted that implementations conform‐
200 ing to the System Interfaces volume of IEEE Std 1003.1-2001 do not take
201 leap seconds into account when computing seconds since the Epoch. When
202 SS=60 is used, the resulting time always refers to 1 plus seconds since
203 the Epoch for a time when SS=59.
204
205 Although the -t time option-argument specifies values in 1969, the
206 access time and modification time fields are defined in terms of sec‐
207 onds since the Epoch (00:00:00 on 1 January 1970 UTC). Therefore,
208 depending on the value of TZ when touch is run, there is never more
209 than a few valid hours in 1969 and there need not be any valid times in
210 1969.
211
212 One ambiguous situation occurs if -t time is not specified, -r ref_file
213 is not specified, and the first operand is an eight or ten-digit deci‐
214 mal number. A portable script can avoid this problem by using:
215
216
217 touch -- file
218
219 or:
220
221
222 touch ./file
223
224 in this case.
225
227 None.
228
230 The functionality of touch is described almost entirely through refer‐
231 ences to functions in the System Interfaces volume of
232 IEEE Std 1003.1-2001. In this way, there is no duplication of effort
233 required for describing such side effects as the relationship of user
234 IDs to the user database, permissions, and so on.
235
236 There are some significant differences between the touch utility in
237 this volume of IEEE Std 1003.1-2001 and those in System V and BSD sys‐
238 tems. They are upwards-compatible for historical applications from both
239 implementations:
240
241 1. In System V, an ambiguity exists when a pathname that is a decimal
242 number leads the operands; it is treated as a time value. In BSD,
243 no time value is allowed; files may only be touched to the current
244 time. The -t time construct solves these problems for future con‐
245 forming applications (note that the -t option is not historical
246 practice).
247
248 2. The inclusion of the century digits, CC, is also new. Note that a
249 ten-digit time value is treated as if YY, and not CC, were speci‐
250 fied. The caveat about the range of dates following the Epoch was
251 included as recognition that some implementations are not able to
252 represent dates beyond 18 January 2038 because they use signed int
253 as a time holder.
254
255 The -r option was added because several comments requested this capa‐
256 bility. This option was named -f in an early proposal, but was changed
257 because the -f option is used in the BSD version of touch with a dif‐
258 ferent meaning.
259
260 At least one historical implementation of touch incremented the exit
261 code if -c was specified and the file did not exist. This volume of
262 IEEE Std 1003.1-2001 requires exit status zero if no errors occur.
263
265 Applications should use the -r or -t options.
266
268 date , the System Interfaces volume of IEEE Std 1003.1-2001, creat(),
269 time(), utime(), the Base Definitions volume of IEEE Std 1003.1-2001,
270 <sys/stat.h>
271
273 Portions of this text are reprinted and reproduced in electronic form
274 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
275 -- Portable Operating System Interface (POSIX), The Open Group Base
276 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
277 Electrical and Electronics Engineers, Inc and The Open Group. In the
278 event of any discrepancy between this version and the original IEEE and
279 The Open Group Standard, the original IEEE and The Open Group Standard
280 is the referee document. The original Standard can be obtained online
281 at http://www.opengroup.org/unix/online.html .
282
283
284
285IEEE/The Open Group 2003 TOUCH(P)