touch Command

Purpose

Updates the access and modification times of a file.

Syntax

touch -a ] [  -c ] [  -m ] [  -f ] [  -r RefFile ] [ Time -t Time  | -d date_time] { File ... | Directory ... }
Note: The preceding syntax is applicable only when the UNIX03 mode is not enabled in the AIX® operating system.

touch [-a f] [-r ref_file | -t time | -d date_time ] file... | Directory

Note: The preceding syntax is applicable only when the UNIX03 mode is enabled. To enable the UNIX03 mode in the AIX operating system, you must set the value of the XPG_SUS_ENV environment variable to ON.

Description

The touch command updates the access and modification times of each file specified by the File parameter of each directory specified by the Directory parameter. If you do not specify a value for the Time variable, the touch command uses the current time. If you specify a file that does not exist, the touch command creates the file unless you specify the -c flag.

The return code from the touch command is the number of files for which the times could not be successfully modified (including files that did not exist and were not created).

The -a and -m flags are active even when you do not specify them in the touch command.

Flags

Item Description
-a Changes the access time of the file specified by the File variable. Does not change the modification time unless -m is also specified.
-c Does not create the file if it does not already exist. No diagnostic messages are written concerning this condition.
-d Date_Time Uses the specified date and time instead of the current time. The date_time variable is specified in the decimal format, YYYY-MM-DDThh:mm:SS[.frac][tz] or YYYY-MM-DDThh:mm:SS[,frac][tz], where:
YYYY
Specifies the four digits of the year (0000 to 9999).
MM
Specifies the month of the year (01 to 12).
DD
Specifies the day of the month (01 to 31).
hh
Specifies the hour of the day (00 to 23).
mm
Specifies the minute of the hour (00 to 59).
SS
Specifies the second of the minute (00 to 59).
T
Indicates a time designator and can be replaced with a single space.
[.frac]
Specifies a fractional second. It can either be blank or a period (.) followed by one or more decimal digits.
[,frac]
Specifies a fractional second. It is a comma (,) followed by one or more decimal digits.
[tz]
If the value of the [tz] parameter is blank, the local time zone is used for the resulting time. If the value of the [tz] parameter is a character Z, the Coordinate Time Zone (UTC) is used for the resulting time. If the value of the [tz] parameter is blank, the value of the TimezoneInfo (TZ) environment variable is used to identify the resulting time. The value of the [tz] parameter is implementation-specific if the resulting time is earlier than the Epoch time. Also, if the resulting time cannot be represented as a timestamp of the file that is specified by the File parameter, the touch command exits with an error status.
-f Attempts to force the touch in spite of read and write permissions on a file.
-m Changes the modification time of File. Does not change the access time unless -a is also specified.
-r RefFile Uses the corresponding time of the file specified by the RefFile variable instead of the current time.
Time Specifies the date and time of the new timestamp in the format MMDDhhmm[YY], where:
MM
Specifies the month of the year (01 to 12).
DD
Specifies the day of the month (01 to 31).
hh
Specifies the hour of the day (00 to 23).
mm
Specifies the minute of the hour (00 to 59).
YY
Specifies the last two digits of the year. If the YY variable is not specified, the default value is the current year (70 to 99 or 00 to 37).

If the value of the YY digits is between 70 and 99, the century is assumed to be 19.

If the value of the YY digits is between 00 and 37, the century is assumed to be 20.

-t Time Uses the specified time instead of the current time. The Time variable is specified in the decimal form [[CC]YY]MMDDhhmm[.SS] where:
CC
Specifies the first two digits of the year (19 to 21).
YY
Specifies the last two digits of the year (00 to 99).

If the value of the YY digits is between 70 and 99, the value of the CC digits is assumed to be 19.

If the value of the YY digits is between 00 and 37, the value of the CC digits is assumed to be 20.

For years after 2038, specify the year in the yyyy format.

MM
Specifies the month of the year (01 to 12).
DD
Specifies the day of the month (01 to 31).
hh
Specifies the hour of the day (00 to 23).
mm
Specifies the minute of the hour (00 to 59).
SS
Specifies the second of the minute (00 to 59).
   
Note:
  1. The touch command calls the utimenstat() subroutine to change the modification and access times of the file touched. This may cause the touch command to fail when flags are used if you do not actually own the file, even though you may have write permission to the file.
  2. Do not specify the full path name /usr/bin/touch if you receive an error message when using the touch command.

Exit Status

This command returns the following exit values:

Item Description
0 The command executed successfully. All requested changes were made.
>0 An error occurred.

Security

hm

Attention RBAC users and Trusted AIX users: This command can perform privileged operations. Only privileged users can run privileged operations. For more information about authorizations and privileges, see Privileged Command Database in Security. For a list of privileges and the authorizations associated with this command, see the lssecattr command or the getcmdattr subcommand.

Examples

  1. To update the access and modification times of a file, enter:
    touch program.c
    This sets the last access and modification times of the program.c file to the current date and time. If the program.c file does not exist, the touch command 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 the last modification times (not the access times) of the files that end with a .o extension in the current directory. 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  -t 02171425 program.c
    This sets the access and modification dates to 14:25 (2:25 p.m.) February 17 of the current year.
  5. To use the time stamp of another file instead of the current time, enter:
    touch  -r file1 program.c
    This gives the program.c file the same time stamp as the file1 file.
  6. To touch a file using a specified time other than the current time, enter:
    touch  -t 198503030303.55 program.c
    This gives the program.c file a time stamp of 3:03:55 a.m. on March 3, 1985.

Files

Item Description
/usr/bin/touch Contains the touch command.