manpagez: man pages & more
info coreutils
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.4 touch: Change file timestamps

touch changes the access and/or modification times of the specified files. Synopsis:

 
touch [option]… file

Any file argument that does not exist is created empty.

A file argument string of ‘-’ is handled specially and causes touch to change the times of the file associated with standard output.

If changing both the access and modification times to the current time, touch can change the timestamps for files that the user running it does not own but has write permission for. Otherwise, the user must own the files.

Although touch provides options for changing two of the times—the times of last access and modification—of a file, there is actually a third one as well: the inode change time. This is often referred to as a file's ctime. The inode change time represents the time when the file's meta-information last changed. One common example of this is when the permissions of a file change. Changing the permissions doesn't access the file, so the atime doesn't change, nor does it modify the file, so the mtime doesn't change. Yet, something about the file itself has changed, and this must be noted somewhere. This is the job of the ctime field. This is necessary, so that, for example, a backup program can make a fresh copy of the file, including the new permissions value. Another operation that modifies a file's ctime without affecting the others is renaming. In any case, it is not possible, in normal operations, for a user to change the ctime field to a user-specified value.

Time stamps assume the time zone rules specified by the TZ environment variable, or by the system default rules if TZ is not set. See (libc)TZ Variable section `Specifying the Time Zone with TZ' in The GNU C Library. You can avoid ambiguities during daylight saving transitions by using UTC time stamps.

The program accepts the following options. Also see Common options.

-a
--time=atime
--time=access
--time=use

Change the access time only.

-c
--no-create

Do not create files that do not exist.

-d
--date=time

Use time instead of the current time. It can contain month names, time zones, ‘am’ and ‘pm’, ‘yesterday’, etc. For example, ‘--date="2004-02-27 14:19:13.489392193 +0530"’ specifies the instant of time that is 489,392,193 nanoseconds after February 27, 2004 at 2:19:13 PM in a time zone that is 5 hours and 30 minutes east of UTC. See section Date input formats. File systems that do not support high-resolution time stamps silently ignore any excess precision here.

-f

Ignored; for compatibility with BSD versions of touch.

-m
--time=mtime
--time=modify

Change the modification time only.

-r file
--reference=file

Use the times of the reference file instead of the current time. If this option is combined with the ‘--date=time’ (‘-d time’) option, the reference file's time is the origin for any relative times given, but is otherwise ignored. For example, ‘-r foo -d '-5 seconds'’ specifies a time stamp equal to five seconds before the corresponding time stamp for ‘foo’.

-t [[CC]YY]MMDDhhmm[.ss]

Use the argument (optional four-digit or two-digit years, months, days, hours, minutes, optional seconds) instead of the current time. If the year is specified with only two digits, then CC is 20 for years in the range 0 … 68, and 19 for years in 69 … 99. If no digits of the year are specified, the argument is interpreted as a date in the current year.

On older systems, touch supports an obsolete syntax, as follows. If no timestamp is given with any of the ‘-d’, ‘-r’, or ‘-t’ options, and if there are two or more files and the first file is of the form ‘MMDDhhmm[YY]’ and this would be a valid argument to the ‘-t’ option (if the YY, if any, were moved to the front), and if the represented year is in the range 1969–1999, that argument is interpreted as the time for the other files instead of as a file name. This obsolete behavior can be enabled or disabled with the _POSIX2_VERSION environment variable (see section Standards conformance), but portable scripts should avoid commands whose behavior depends on this variable. For example, use ‘touch ./12312359 main.c’ or ‘touch -t 12312359 main.c’ rather than the ambiguous ‘touch 12312359 main.c’.

An exit status of zero indicates success, and a nonzero value indicates failure.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© manpagez.com 2000-2017
Individual documents may contain additional copyright information.