Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

touch - change file access and modification times

&pagelevel(4)&pagelevel

touch is used to set the access and modification times of files to the current or specified date.


Syntax


Format 1:touch[ -acm][-r ref_file | -t time] file ...
Format 2:touch[ -acm][ MMDDhhmm[yy]] file ...



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


No option specified

touch sets the last modification and access times for the specified files to the specified or current date. If a file does not yet exist then touch creates it. touch without an option therefore has the same effect as touch -am.


-a

(access time)

touch sets the the last access time for the specified files to the specified or current date.

If neither -a nor -m is specified:
touch sets the access and modification times of the named files to the specified or current date.

-c

touch does not create files which do not exist. In such a case, no message is output.

-m

(modification time)

touch sets the last modification time for the specified files to the specified or current date.

Neither -a nor -m specified:
touch sets the last access and modification time for the specified files to the specified or current date.

-r ref_file

Instead of the current time, touch uses the corresponding date and time from ref_file.

-t time

Instead of the current time, touch uses the time specified in time. time is output as a decimal number with the following format:
[[CC]YY]MMDDhhmm[.SS]

CC:

The first two figures of the year specification (century). The century specification is optional. If you do not specify a century, the current century is used.

YY:

The last two figures of the year specification (decade and year). The decade and year specification is optional. If no decade and year are specified, the current decade and year are used.

If the decade and year are specified but the century CC is not, then CC is calculated as follows:

for 69<=YY<=99 CC is 19
for 00<=YY<=38 CC is 20

MM:

Month (01-12)

DD:

Day (01-31)

hh:

Hours (00-23)

mm:

Minutes (00-59)

SS:

Seconds (00-61). The seconds specification is optional. If you do not specify SS then the value 00 is used.

If you wish to specify the seconds, the value of SS must be in the range 00-61 (instead of the usual range 00-59). The values 60 and 61 should be considered as reserve seconds.

The highest date you can specify for time is:

20380119031407

CCYYMMDDhhmmss

file

Name of the input file. touch processes all types of files, including directories. Several file names may be specified in one call.
Completely numeric file names may cause problems, as touch may interpret them as date arguments.



Format 2:touch[ -acm][ MMDDhhmm[yy]] file ...


No option specified

touch sets the access and modification times of the named files to the specified or current date. If a file does not exist, it is created. Calling touch without options is thus equivalent to touch -am.

-a

(access time)

updates only the access time of the named files to the specified or current date.

If neither -a nor -m is specified:
touch sets the access and modification times of the named files to the specified or current date.

-c

Prevents touch from creating a file if the named file did not previously exist. No corresponding message is issued.

-m

(modification time)

Updates only the modification time of the named files to the specified or current date.

If neither -a nor -m is specified:
touch sets both the access and modification times of the named files to the specified or current date.

MMDDhhmm[YY]

Date and time to which the access and/or modification times of the specified files are to be set. The date/time argument comprises eight to ten digits with the following significance:
month (MM) - day (DD) - hour (hh) - minute (mm) - year (YY)

If you specify the year YY but not the millennium CC, CC is inferred as follows:

with 69<=YY<=99, CC is 19
with 00<=YY<=38, CC is 20

The highest date you can specify for time is:

0119031438

MMDDhhmmYY

YY not specified:
touch assumes you mean the current year.

MMDDhhmm[YY] not specified:
The access and/or modification times of each named file are set to the current date and time by default.

file

Name of the input file. touch processes all types of files, including directories. Several file names may be specified in one call.
Completely numeric file names may cause problems, as touch may interpret them as date arguments.

Error

date: bad date conversion

You have specified an illegal date, e.g. 13010000.


Variable

TZ

Determine the timezone to be used for interpreting the time option argument.

Locale

The following environment variables affect the execution of touch:

LANG

Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined.

LC_ALL

If set to a non-empty string value, override the values of all the other internationalization variables.

LC_CTYPE

Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files), the classification of characters as upper- to lower-case, and the mapping of characters from one case to the other.

LC_MESSAGES

Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.

NLSPATH

Determine the location of message catalogs for the processing of LC_MESSAGES.

Example 1

Set the access and modification times of file to the current date. No new file is to be created if this file does not exist.

$ touch -c file

The ls -l command can be used to display the time of the last modification; ls -lu outputs the access time.

Example 2

Set the access time of file to 9 o’clock on 8/26:

$ touch -a 08260900 file

$ ls -lu file

-rw-r--r--   1 BERT    qm2         736  Aug 26 09:00 file

See also

date, ls
utime() [4]