Updates the access and modification times of a file.
touch [ -a ] [ -c ] [ -m ] [ -f ] [ -r RefFile ] [ Time | -t Time ] { File ... | Directory ... }
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).
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. |
-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:
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:
|
This command returns the following exit values:
Item | Description |
---|---|
0 | The command executed successfully. All requested changes were made. |
>0 | An error occurred. |
hm
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.touch -c program.c
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.touch -r file1 program.c
This gives the program.c file the same time stamp as the file1 file.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.Item | Description |
---|---|
/usr/bin/touch | Contains the touch command. |