touch — Change the file access and modification times
Format
touch [–acm] [–f agefile] [–r agefile] [–t time] file …
touch [–acm] time file …
Description
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. It maintains the correct release times for software and is useful with the make command.
Options
- –a
- Sets only the access time.
- –c
- Does not create any file that does not 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.
- –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 times 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)
[[mm]dd]hhmm[.ss]
or: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
, enter:oldfile
touch –r oldfile newfile
Environment variables
- TZ
- Contains the time zone that touch is to use when interpreting times.
Format of the TZ environment variable explains how to set the local time zone with the TZ environment variable.
Localization
- LANG
- LC_ALL
- LC_CTYPE
- LC_MESSAGES
- NLSPATH
See Localization for more information.
Exit values
- 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
- 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 information
cp, date
Format of the TZ environment variable explains how to set the local time zone with the TZ environment variable.