touch — Change the file access and modification times
touch [–acm] [–f agefile] [–r agefile] [–t time] file ...
touch [–acm] time file ...
touch [–acm] time file ...
Purpose
The touch command changes certain dates for each file argument. By default, touch sets both the date of last file modification and the date of last file access to the current time. This is useful for maintaining correct release times for software and is particularly useful in conjunction with the make command.
Options
- –a
- Sets only the access time.
- –c
- Does not create any file that does not already exist. Normally, touch creates such files.
- –m
- Sets only the modification time.
If you do not specify –a or –m, touch behaves as though you specified both.
To tell touch to use a time other than the current, use one of the following options:
- –f agefile
- Is an obsolete version of the –r option.
- –r agefile
- Sets the access and modification times (as indicated by the other options) to those kept for agefile.
- –t time
- specifies a particular time using this format:
[[[[cc]yy]mm]dd]hhmm [.ss]
where:- cc is the first two digits of the year (optional)
- yy is the last two digits of the year (optional)
- mm is the number of the month (01—12) (optional)
- dd is the day of the month (optional)
- hh is the hour in 24-hour format (required)
- mm is the minutes (required)
- ss is the seconds (optional)
An obsolete (but still supported) version of this command lets you omit the –t, but the format is:
or:[[mm]dd]hhmm[.ss]
mmddhhmmyy[.ss]
Examples
- To set the modification time of newfile to the present, enter:
touch newfile
- To set the modification time of oldfile to 13:05 on July 3, 1994, enter:
touch -t 9407031305 oldfile
- To set the modification time of newfile to that of oldfile, enter:
touch -r oldfile newfile
Environment Variables
- TZ
- Contains the time zone that touch is to use when interpreting times.
Localization
touch uses the following localization environment variables:
- LANG
- LC_ALL
- LC_CTYPE
- LC_MESSAGES
Exit Values
Possible exit status values are:
0
- Successful completion
1
- Failure due to any of the following:
- Inability to access the desired file
- Too early a date was specified
- Inability to create a file
- Inability to change a file's times
2
- Failure that resulted in a usage message, including:
- Unknown command-line option
- Only one of –t, –f, or –r is allowed
- –r was missing the agefile
- –t was missing its argument
- Incorrect date string
Messages and Return Codes
Possible error messages include:
- Age file inaccessible
- Indicates that time could not be found for the file given with the –f or –r option either because that file does not exist or because the requesting user is not granted the appropriate permission for the file.
- Missing age file argument
- You specified –f or –r, but did not give a file name after it.
- Years earlier than year incorrect
- Your system recognizes dates only back to the given year. touch does not accept dates before that time.
- Bad date conversion
- Only one –r, –f, or –t flag allowed
- Missing the date or time argument
Portability
POSIX.2, X/Open Portability Guide, UNIX systems.
Related Commands
cp, date