xref: /freebsd/usr.bin/touch/touch.1 (revision aa1a8ff2d6dbc51ef058f46f3db5a8bb77967145)
1.\" Copyright (c) 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" the Institute of Electrical and Electronics Engineers, Inc.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.Dd June 1, 2018
32.Dt TOUCH 1
33.Os
34.Sh NAME
35.Nm touch
36.Nd change file access and modification times
37.Sh SYNOPSIS
38.Nm
39.Op Fl A Ar [-][[hh]mm]SS
40.Op Fl achm
41.Op Fl r Ar file
42.Op Fl t Ar [[CC]YY]MMDDhhmm[.SS]
43.Op Fl d Ar YYYY-MM-DDThh:mm:SS[.frac][tz]
44.Ar
45.Sh DESCRIPTION
46The
47.Nm
48utility sets the modification and access times of files.
49If any file does not exist, it is created with default permissions.
50.Pp
51By default,
52.Nm
53changes both modification and access times.
54The
55.Fl a
56and
57.Fl m
58flags may be used to select the access time or the modification time
59individually.
60Selecting both is equivalent to the default.
61By default, the timestamps are set to the current time.
62The
63.Fl d
64and
65.Fl t
66flags explicitly specify a different time, and the
67.Fl r
68flag specifies to set the times those of the specified file.
69The
70.Fl A
71flag adjusts the values by a specified amount.
72.Pp
73The following options are available:
74.Bl -tag -width Ds
75.It Fl A
76Adjust the access and modification time stamps for the file by the
77specified value.
78This flag is intended for use in modifying files with incorrectly set
79time stamps.
80.Pp
81The argument is of the form
82.Dq [-][[hh]mm]SS
83where each pair of letters represents the following:
84.Pp
85.Bl -tag -width Ds -compact -offset indent
86.It Ar -
87Make the adjustment negative: the new time stamp is set to be before
88the old one.
89.It Ar hh
90The number of hours, from 00 to 99.
91.It Ar mm
92The number of minutes, from 00 to 59.
93.It Ar SS
94The number of seconds, from 00 to 59.
95.El
96.Pp
97The
98.Fl A
99flag implies the
100.Fl c
101flag: if any file specified does not exist, it will be silently ignored.
102.It Fl a
103Change the access time of the file.
104The modification time of the file is not changed unless the
105.Fl m
106flag is also specified.
107.It Fl c
108Do not create the file if it does not exist.
109The
110.Nm
111utility does not treat this as an error.
112No error messages are displayed and the exit value is not affected.
113.It Fl d
114Change the access and modification times to the specified date time instead
115of the current time of day.
116The argument is of the form
117.Dq YYYY-MM-DDThh:mm:SS[.frac][tz]
118where the letters represent the following:
119.Bl -tag -width Ds -compact -offset indent
120.It Ar YYYY
121At least four decimal digits representing the year.
122.It Ar MM , Ar DD , Ar hh , Ar mm , Ar SS
123As with
124.Fl t
125time.
126.It Ar T
127The letter
128.Li T
129or a space is the time designator.
130.It Ar .frac
131An optional fraction, consisting of a period or a comma followed by one or
132more digits.
133The number of significant digits depends on the kernel configuration and the
134filesystem, and may be zero.
135.It Ar tz
136An optional letter
137.Li Z
138indicating the time is in
139.Tn UTC .
140Otherwise, the time is assumed to be in local time.
141Local time is affected by the value of the
142.Ev TZ
143environment variable.
144.El
145.It Fl h
146If the file is a symbolic link, change the times of the link
147itself rather than the file that the link points to.
148Note that
149.Fl h
150implies
151.Fl c
152and thus will not create any new files.
153.It Fl m
154Change the modification time of the file.
155The access time of the file is not changed unless the
156.Fl a
157flag is also specified.
158.It Fl r
159Use the access and modifications times from the specified file
160instead of the current time of day.
161.It Fl t
162Change the access and modification times to the specified time instead
163of the current time of day.
164The argument is of the form
165.Dq [[CC]YY]MMDDhhmm[.SS]
166where each pair of letters represents the following:
167.Pp
168.Bl -tag -width Ds -compact -offset indent
169.It Ar CC
170The first two digits of the year (the century).
171.It Ar YY
172The second two digits of the year.
173If
174.Dq YY
175is specified, but
176.Dq CC
177is not, a value for
178.Dq YY
179between 69 and 99 results in a
180.Dq CC
181value of 19.
182Otherwise, a
183.Dq CC
184value of 20 is used.
185.It Ar MM
186The month of the year, from 01 to 12.
187.It Ar DD
188the day of the month, from 01 to 31.
189.It Ar hh
190The hour of the day, from 00 to 23.
191.It Ar mm
192The minute of the hour, from 00 to 59.
193.It Ar SS
194The second of the minute, from 00 to 60.
195.El
196.Pp
197If the
198.Dq CC
199and
200.Dq YY
201letter pairs are not specified, the values default to the current
202year.
203If the
204.Dq SS
205letter pair is not specified, the value defaults to 0.
206.El
207.Sh EXIT STATUS
208.Ex -std
209.Sh COMPATIBILITY
210The obsolescent form of
211.Nm ,
212where a time format is specified as the first argument, is supported.
213When no
214.Fl r
215or
216.Fl t
217option is specified, there are at least two arguments, and the first
218argument is a string of digits either eight or ten characters in length,
219the first argument is interpreted as a time specification of the form
220.Dq MMDDhhmm[YY] .
221.Pp
222The
223.Dq MM ,
224.Dq DD ,
225.Dq hh
226and
227.Dq mm
228letter pairs are treated as their counterparts specified to the
229.Fl t
230option.
231If the
232.Dq YY
233letter pair is in the range 39 to 99, the year is set to 1939 to 1999,
234otherwise, the year is set in the 21st century.
235.Sh SEE ALSO
236.Xr utimensat 2
237.Sh STANDARDS
238The
239.Nm
240utility is expected to be a superset of the
241.St -p1003.2
242specification.
243.Sh HISTORY
244A
245.Nm
246utility appeared in
247.At v7 .
248