xref: /freebsd/usr.bin/touch/touch.1 (revision 3481910d32826e5363e3f6a39a031d3750b58420)
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. All advertising materials mentioning features or use of this software
16.\"    must display the following acknowledgement:
17.\"	This product includes software developed by the University of
18.\"	California, Berkeley and its contributors.
19.\" 4. Neither the name of the University nor the names of its contributors
20.\"    may be used to endorse or promote products derived from this software
21.\"    without specific prior written permission.
22.\"
23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33.\" SUCH DAMAGE.
34.\"
35.\"     @(#)touch.1	8.3 (Berkeley) 4/28/95
36.\" $FreeBSD$
37.\"
38.Dd April 28, 1995
39.Dt TOUCH 1
40.Os
41.Sh NAME
42.Nm touch
43.Nd change file access and modification times
44.Sh SYNOPSIS
45.Nm
46.Op Fl A Ar [-][[hh]mm]SS
47.Op Fl acfhm
48.Op Fl r Ar file
49.Op Fl t Ar [[CC]YY]MMDDhhmm[.SS]
50.Ar
51.Sh DESCRIPTION
52The
53.Nm
54utility sets the modification and access times of files.
55If any file does not exist, it is created with default permissions.
56.Pp
57By default,
58.Nm
59changes both modification and access times.  The
60.Fl a
61and
62.Fl m
63flags may be used to select the access time or the modification time
64individually.
65Selecting both is equivalent to the default.
66The base times for the modification are both set to the current time.
67The
68.Fl t
69flag explicitly specifies a single time for both values, and the
70.Fl r
71flag specifies to set the times from those of a different file.
72The
73.Fl A
74flag adjusts the values by a specified amount.
75This adjustment is done after first establishing the base times.
76.Pp
77The following options are available:
78.Bl -tag -width Ds
79.It Fl A
80Adjust the access and modification time stamps for the file by the
81specified value.
82This flag is intended for use in modifying files with a time stamp
83relative to an incorrect time zone.
84It always modifies both the access time and the modification time.
85.Pp
86The argument is of the form
87.Dq [-][[hh]mm]SS
88where each pair of letters represents the following:
89.Pp
90.Bl -tag -width Ds -compact -offset indent
91.It Ar -
92Make the adjustment negative: the new time stamp is set to be before
93the old one.
94.It Ar hh
95The hour of the day, from 00 to 23.
96.It Ar mm
97The minute of the hour, from 00 to 59.
98.It Ar SS
99The second of the minute, from 00 to 59.
100.El
101.Pp
102When used in conjunction with the
103.Fl a
104flag only, the modification time is adjusted by the time specified as
105argument to the
106.Fl A
107flag, while the access time is modified from the base time described
108above.
109Similarly, when used in conjunction with the
110.Fl m
111flag only, the access time is adjusted by the time specified as
112argument to the
113.Fl A
114flag, while the access time is modified from the base time described
115above.
116.Pp
117If the file does not exist, and creation is allowed,
118.Fl A
119does not change its time stamps.
120.It Fl a
121Change the access time of the file.
122The modification time of the file is not changed unless one of the
123.Fl A
124or
125.Fl m
126flags is also specified.
127.It Fl c
128Do not create the file if it does not exist.
129The
130.Nm
131utility does not treat this as an error.
132No error messages are displayed and the exit value is not affected.
133.It Fl f
134Attempt to force the update, even if the file permissions do not
135currently permit it.
136.It Fl h
137If the file is a symbolic link, change the times of the link
138itself rather than the file that the link points to.
139Note that
140.Fl h
141implies
142.Fl c
143and thus will not create any new files.
144.It Fl m
145Change the modification time of the file.
146The access time of the file is not changed unless one of the
147.Fl A
148or
149.Fl a
150flags is also specified.
151.It Fl r
152Use the access and modifications times from the specified file
153instead of the current time of day.
154.It Fl t
155Change the access and modification times to the specified time.
156The argument is of the form
157.Dq [[CC]YY]MMDDhhmm[.SS]
158where each pair of letters represents the following:
159.Pp
160.Bl -tag -width Ds -compact -offset indent
161.It Ar CC
162The first two digits of the year (the century).
163.It Ar YY
164The second two digits of the year.
165If
166.Dq YY
167is specified, but
168.Dq CC
169is not, a value for
170.Dq YY
171between 69 and 99 results in a
172.Dq CC
173value of 19.
174Otherwise, a
175.Dq CC
176value of 20 is used.
177.It Ar MM
178The month of the year, from 01 to 12.
179.It Ar DD
180the day of the month, from 01 to 31.
181.It Ar hh
182The hour of the day, from 00 to 23.
183.It Ar mm
184The minute of the hour, from 00 to 59.
185.It Ar SS
186The second of the minute, from 00 to 61.
187.El
188.Pp
189If the
190.Dq CC
191and
192.Dq YY
193letter pairs are not specified, the values default to the current
194year.
195If the
196.Dq SS
197letter pair is not specified, the value defaults to 0.
198.El
199.Sh EXIT STATUS
200.Ex -std
201.Sh COMPATIBILITY
202The obsolescent form of
203.Nm ,
204where a time format is specified as the first argument, is supported.
205When no
206.Fl r
207or
208.Fl t
209option is specified, there are at least two arguments, and the first
210argument is a string of digits either eight or ten characters in length,
211the first argument is interpreted as a time specification of the form
212.Dq MMDDhhmm[YY] .
213.Pp
214The
215.Dq MM ,
216.Dq DD ,
217.Dq hh
218and
219.Dq mm
220letter pairs are treated as their counterparts specified to the
221.Fl t
222option.
223If the
224.Dq YY
225letter pair is in the range 39 to 99, the year is set to 1939 to 1999,
226otherwise, the year is set in the 21st century.
227.Sh SEE ALSO
228.Xr utimes 2
229.Sh STANDARDS
230The
231.Nm
232utility is expected to be a superset of the
233.St -p1003.2
234specification.
235.Sh HISTORY
236A
237.Nm
238utility appeared in
239.At v7 .
240