touch(1) — Commands
NAME
touch − Updates file access and modification times
SYNOPSIS
touch [-acfm] [-r reference_file | -t time] file ...
The following older syntax is now maintained for backward compatibility, but may be withdrawn in future issues: touch touch [-acfm] [time] file ...
FLAGS
-aChanges only the access time.
-cSuppresses the creation of the file.
-fAttempts to force the touch in spite of read and write permissions on a file. -f is actually a dummy flag; it is not used by the touch code, but is recognized by getopt().
-mChanges only the modification time.
-r reference_file
Uses the time of the file named by the pathname reference_file instead of the current time. You cannot use -r and -t together.
-t timeUses the specified time instead of the current time.
The time argument is a decimal number in the following form:
[[CC]YY]MMDDhhmm[.SS]
The paired decimal numbers in the preceding syntax line represent the following:
CCThe first two digits of the year (the century)
YYThe second two digits of the year (00-99)
MMThe month of the year (01-12)
DDThe day of the month (01-31)
hhThe hour of the day (00-23)
mmThe minute of the hour (00-59)
SSThe second of the minute (00-61)
Both CC and YY are optional. If neither is specified, the current year is assumed. If YY is specified, but CC is not, CC is derived as follows:
If YY is 69-99, CC is 19.
If YY is 00-68, CC is 20.
The resulting time is affected by the value of the TZ environment variable. If the resulting time value precedes the Epoch, touch exits immediately with an error status. The range of valid times past the Epoch extends to at least midnight 1 January 2000 UCT.
The range for SS is 00-61 rather than 00-59 because of leap seconds. If SS is 60 or 61, and the resulting time, as affected by the TZ environment variable, does not refer to a leap second, the resulting time is one or two seconds after a time where SS is 59. If SS is not given a value, it is assumed to be 0 (zero).
DESCRIPTION
The touch command updates the access and modification times of each file or directory named to the one specified on the command line or to the current time if you do not specify a time. You can specify the time with -t or by the time of the reference file with the -r option. If you do not specify a time, touch uses the current time. If you specify a file that does not exist, touch creates a file with that name unless you request otherwise with the -c flag.
If neither the -a or -m flags are specified, touch behaves as though both of these flags were specified.
The LC_TIME environment variable, if defined, specifies the order of month and day in the date specification and of hour and minute in the time specification. Otherwise, these orders default to MMdd and hhmm. The format for the time argument is MMddhhmm[yy].
The obsolescent format for the time argument is MMddhhmm[yy].
EXAMPLES
1.To update the access and modification times of a file, enter:
touch program.c
This sets the last access and last modification times of program.c to the current date and time. If program.c does not exist, touch creates an empty file with that name.
2.To avoid creating a new file, enter:
touch -c program.c
3.To update only the modification time, enter:
touch -m ∗.o
This updates only the last modification times of the files in the current directory that end with .o. The touch command is often used in this way to alter the results of the make command.
4.To explicitly set the access and modification times, enter:
touch -c 02171425 program.c
This sets the access and modification dates to 14:25 (2:25 p.m.) February 17 of the current year. (This assumes that you are using the default format.)
5.To touch a file with a numeric filename, include its full pathname or precede it with ./, so that the filename is not mistaken for the time argument. For example, to touch the file 123.abc, enter:
touch -c ./123.abc
EXIT VALUES
The return code from touch is the number of files whose times could not be successfully modified (including files that did not exist and were not created). If no errors occur, the exit status is 0 (zero).
RELATED INFORMATION
Commands: date(1).
Functions: utime(2).
Files: locale(4).