[Previous] [Contents] [Index] [Next]

touch

Change file access and modification times (POSIX)

Syntax:

touch [-acm] [-r ref_file|-t time] file...

Options:

-a
Change the access time of file to time, or to the current time if time isn't specified. Don't change the modification time unless the -m option is also specified.
-c
If file doesn't already exist, don't create file and don't write any diagnostic messages concerning this condition.
-m
Change the modification time of file to time, or to the current time if time isn't specified. Don't change the access time unless -a is also specified.
-r ref_file
Use the specified reference file's modification time instead of the current time.
-t time
Use the specified time instead of the current time, where time is a decimal number of the form:

[[CC]YY]MMDDhhmm[.SS]

The two-digit pairs in time represent the following:

CC
The first two digits of the year (i.e. the century).
YY
The second two digits of the year.
MM
The month of the year (01-12).
DD
The day of the month (01-31).
hh
The hour of the day (00-23).
mm
The minute of the hour (00-59).
SS
The second of the minute (00-61).

Both CC and YY are optional. If you specify neither of these, the current year is assumed. If you specify YY, but you don't specify CC, CC is derived as follows:

If YY is:  CC becomes:
69-99 19
00-68 20

The resulting time is affected by the value of the TZ environment variable (see below). If the resulting time precedes 0 hours, 0 minutes, 0 seconds, January 1, 1970 Coordinated Universal Time (i.e. the Epoch), touch exits immediately with an error status.

The range for SS is 00-61 rather than 00-59 to allow for leap seconds. If SS is 60 or 61, and the resulting time -- as affected by the TZ environment variable -- doesn't refer to a leap second, the resulting time is one second after a time where SS is 59. If you don't give a value to SS, it's assumed to be 0.

file
The pathname of a file whose times are to be modified.

Description:

The touch utility lets you change either the modification times or access times of files, or both.

If any file you specify doesn't exist, the file is created unless you specify the -c option. If no time is specified, the current time is used. The -a option changes only the access time of the file; the -m option changes only the modification time of the file.

If you don't specify any options, touch behaves as if you used the -a and -m options.

Examples:

Set file1's access and modification time to the current system time:

touch file1

Change file2's access and modification time to be the same as file1's modification time:

touch -r file1 file2

Set file3's access and modification time to December 25, 12:34, using the current year:

touch -t 12251234 file3

Environment variables:

TZ
Specifies the local time for the specified time zone.

Exit status:

0
Successful completion.
>0
An error occurred.

[Previous] [Contents] [Index] [Next]