TOUCH(1) | General Commands Manual | TOUCH(1) |
touch
— change
file access and modification times
touch |
[-acDfhm ] [-d
posix-datetime|human-datetime]
[--date
posix-datetime|human-datetime]
[-R ref-file]
[-r ref-file]
[--reference ref-file]
[-t datetime]
file ... |
The touch
utility changes either or both
of the access and modification times of the files to
the time specified by the options, described below, or to the current time
of day, if none of those options is present. If the file doesn't exist, it
is first created with default permissions.
The following options are available:
-a
-m
flag is also specified.
-c
touch
utility does not treat this as an error. No
error messages are displayed and the exit value is not affected.
-D
-d
posix-datetime-d
human-datetime--date
posix-datetime--date
human-datetimeCCYY
represents a 4 (or more) digit year number,MM
represents a 2 digit month number (1-12),DD
represents a 2 digit day of the month (1-31),T
represents either the character ‘T’ or a single space
character (in which case the space, at least, may need to be quoted to
the shell to avoid the arg being split into two words),hh
represents a 2 digit hour of the day (00-23),mm
represents a 2 digit minute of the hour (00-59),ss
represents a 2 digit second of the minute (00-60) where 60 indicates
the occurrence of a leap second, which POSIX systems ignore, resulting
in the following second being generated instead (:00 of the next
minute),.frac
represents optional factional seconds, where the ‘.’ can
be a period (‘.’) or a comma (‘,’) and
frac
gives one or more digits, interpreted as
if in a floating-point representation of the seconds, so
“.3” represents three tenths of a second, and
“,17” represents seventeen hundredths of a second, etc.
Note that if the period or comma is given, there must be at least one
following digit. If no fraction of a second is to be specified, also
omit the period (or comma). If omitted, the fractional seconds are set
to 0, so specifying “.0” or “,0” is
identical to omitting the .frac
field
entirely,Z
represents an optional literal ‘Z’ character, indicating
the the time given is to be considered as a Co-ordinated Universal
Time (UTC) value. If omitted, the time is considered as being in the
local timezone, as specified by the TZ
environment variable.Note that parsing of this string is quite strict. If successfully parsed, the time to set will be that specified by this string.
If the attempt to parse the string as a
posix-datetime fails, then
touch
will attempt to parse it as a
human-datetime using the human datetime parser
parsedate(3), and use
the result as the time to set.
-f
-h
-c
.
-m
-a
flag is also specified.
-R
ref-file-r
ref-file--reference
ref-file-R
form of this option was used,
the times are taken from the symbolic link itself, otherwise the times are
taken from the file referenced by it. If ref-file is
not a symbolic link, all three forms are identical.
-t
datetimeTZ
environment variable, does not refer to
a leap second, the resulting time is one second after a time where
ss is 59. If ss is not
given a value, it is assumed to be zero, and the preceding period
(‘.’) must be omitted.If the “CC” and “YY” letter pairs are not specified, the values default to the current year. If the “ss” letter pair (and the preceding period) is not specified, the value defaults to 0. As an extension to the standard, any of the “MM”, “DD”, and “hh” fields may also be omitted, defaulting to the current time of day, but once any one of these letter pairs is given, all the following ones (except “.ss”) are required. Fields must always be specified as 2 digits, even when the value is less than 10. Leading zeroes do not cause the value to be treated as octal, all conversions use decimal numbers.
The -d
, -R
,
-r
, and -t
options are
(nominally) mutually exclusive. If more than one of these options is
present, each will be evaluated, and may cause an error, then the result
from the last one specified is used.
The options which specify any part of the time
(-d
, -R,
-r
, -t
) apply to both the
access and modification times (with -r
and
-R
obtaining those values independently from the
ref-file), though which is actually applied depends
upon the -a
and -m
options.
TZ
-t
option, and the default zone for the posix-datetime
or human-datetime argument of the
-d
option.touch -h -r path path
If path is a symbolic link, this will set the symbolic link's access and modify timestamps identical to those of the file to which it refers. If path is not a symbolic link, this will simply update the “inode changed” time (“ctime”) of the path file to the current time of day.
touch -Dh -d human-datetime -t
CCYYMMDDhhmm.ss -R file file
Provided file exists, this parses the
human-datetime and
CCYYMMDDhhmm.ss arguments, verifying that they would
be suitable for use with touch
, then does nothing,
as the final time specification (-R
) specifies to
take the times from file and apply them to
file itself, changing nothing, which the
-D
option then prevents from actually occurring.
That is, this merely tests that the human-datetime and
datetime arguments to -d
and
-t
respectively are valid, and could be used to
specify a time. Use of both -h
and
-R
means this works if file is
a symbolic link, even one which does not reference an existing file, as well
as if it is some other file type. Use of -R
requires
that file exists, though if it does not, and an error
is generated for that reason, the -d
and
-t
arguments would have already been successfully
processed.
touch -m -d '-1 day'
somefile
Set the modify time for somefile to one day (24 hours) earlier than the current time.
The touch
utility exits 0 on
success, and >0 if an error occurs.
The obsolescent form of touch
, where a
time format is specified as the first argument, is supported. When none of
the time setting options is specified, there are at least two arguments, and
the first argument is a string of digits which is either eight or ten
characters in length, the first argument is interpreted as a time
specification of the form “MMDDhhmm[YY]” and applied to the
remaining arguments interpreted as path names.
The “MM”, “DD”, “hh” and
“mm” letter pairs are treated as their counterparts specified
to the -t
option, except that none of these are
optional. If the “YY” letter pair is present, it is interpret
the same as “YY” in the -t
option with
no “CC” specified, however here it appears last, rather than
first. There are no equivalents to the “CC” or
“ss” fields of -t
and the fractional
seconds field is always set to zero.
Sometime in the middle of the 21st century, the default “CC” used in formats where that information is not present, or where those digits are not given, will be altered to make low year numbers represent the 22nd century, and high years the 21st century. The boundary between low and high is also expected to change. To avoid issues, always use formats which include the “CC” field, and always use it when “YY” is given.
The touch
utility is expected to be a
superset of the IEEE Std 1003.2
(“POSIX.2”) and IEEE Std 1003.1-2008
(“POSIX.1”) specifications.
A touch
utility appeared in
Version 7 AT&T UNIX.
February 10, 2024 | NetBSD 10.99 |