Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > T


HP-UX 11i Version 3: February 2007

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index


touch — update access, modification, and/or change times of file


touch [-amc] [-r ref_file | -t time] file_name...


touch time_str file_name...


touch updates the access, modification, and last-change times of each argument. The file name is created if it does not exist. If no time is specified (see date(1)) the current time is used.

The -r and -t options are mutually exclusive.


The following options are available:


Change the access time of file_name to time, or to the current time if time is not specified. Do not change the modification time unless -m is also specified.


Change the modification time of file_name to time, or to the current time if time is not specified. Do not change the access time unless -a is also specified.


Silently prevent touch from creating the file if it did not previously exist. Do not write any diagnostic messages concerning this condition.

-r ref_file

Use the corresponding time of ref_file instead of the current time.

-t time

Use the specified time instead of the current time. The option argument is a decimal number of the form:


where each two digits represents the following:


The first two digits of the year.


The second two digits of the year.


The month of the year (01-12).


The day of the month (01-31).


The hour of the day (00-23).


The minute of the hour (00-59).


The second of the minute (00-61).

If neither CC nor YY is given, the current year is assumed. If YY is specified, but CC is not, CC is derived as follows: (taken into account the local time factor)

If YY is:CC becomes:

If the resulting time value precedes the Epoch (00:00:00 January 1, 1970 Greenwich Mean Time), touch exits immediately with an error status.

The range for SS is 00 through 61 rather than 00 through 59 to accommodate 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 second after a time where SS is 59. If SS is not given a value, it is assumed to be 0.

The syntax shown by the second SYNOPSIS line is recognized when neither the -r option, the -t option, nor the -- option delimiter is specified, and the first operand consists of all decimal digits. This operand is interpreted as the time argument instead of as a file name. However, in this case, time_str is assumed to be of the form:


This is for backward compatibility. The -t form given above is recommended for future portability. The -- option delimiter can be used before the first file_name if there is a possibility that file_name consists of all digits, in order to ensure that the first syntax is used.

touch succeeds only when invoked by the owner of the file if any of the following are true:

  • A time is specified.

  • Only the access time of the file is being updated.

  • Only the modification time of the file is being updated.

In addition, touch succeeds when invoked by a user with write permission on the file if both of the following are true:

  • No time is specified.

  • Both the access time and modification time of the file are being updated.


Environment Variables


If the time is specified via the -t option, TZ is used to interpret the time for the specified time zone.

LC_MESSAGES determines the language in which messages are displayed.

If LC_MESSAGES is not specified in the environment or is set to the empty string, the value of LANG is used as a default for each unspecified or empty variable. If LANG is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of LANG.

If any internationalization variable contains an invalid setting, touch behaves as if all internationalization variables are set to "C". See environ(5).

International Code Set Support

Single- and multibyte character code sets are supported.


touch returns the following values:


All file_name arguments were successfully changed.


Prints out a diagnostic message if an invalid time or a time earlier than the Epoch was specified with the -t option, or if the -r and -t options were both specified, or if one or more of the file_name arguments could not be accessed.


The following command sets the modification and access times of the file named "bastille" to midnight, July 14, 1989, creating the file if it does not already exist.

touch -t 8907140000 bastille

The following command does the same thing using the backward-compatible syntax:

touch 0714000089 bastille

The following command sets the time of the two files named "0714000089" and "bastille" to the current time, creating them if they do not exist:

touch -- 0714000089 bastille

To create a zero-length file, use any of the following:

touch file cat /dev/null >file cp /dev/null file



An attempt to touch a file owned by the superuser on a remote server can fail, even if the invoking user has write permission on the file.


date(1), utime(2).


touch: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.