Touch (Unix)

Touch (Unix)

touch is a standard Unix program used to change a file's access and modification timestamps. It is also used to create a new empty file.

History

A touch utility appeared in Version 7 AT&T UNIX. The version of touch bundled in GNU coreutils was written by Paul Rubin, Arnold Robbins, Jim Kingdon, David MacKenzie and Sunil Sharma.

Specification

The Single Unix Specification (SUS) specifies that touch should change the access times, modification times, or both, for a file. The file is identified by a pathname supplied as a single argument. It also specifies that if the file identified does not exist, the file is created and the access and modification times are set as specified. If no new timestamps are specified, touch uses the current time.

Usage

The SUS mandates the following options:: -a, change the access time only: -c, if the file does not exist, do not create it and do not report this condition: -m, change the modification time only: -r "file", use the access and modification times of "file": -t "time", use the time specified (in the format below) to update the access and modification times

The time is specified in the format [cc] yy] MMDDhhmm [.ss] where MM specifies the two-digit numeric month, DD specifies the two-digit numeric day, hh specifies the two-digit numeric hour, mm specifies the two-digit numeric minutes. Optionally ss specifies the two-digit seconds, cc specifies the first two digits of the year, and yy specifies the last two digits of the year.

Note that if invoked without these options, the standard specifies that the current date and time are used to change the access and modification times. This behaviour simulates an update to a file without having to change it, which may be desirable in certain situations (see the example below).

Other Unix and Unix-like operating systems may add extra options. For example, GNU touch adds a -d option, which enables time input in formats other than that specified.

Examples

The simplest use case for touch is thus: # touch myfile.txtTouch doesn't modify the contents of myfile.txt; it just updates the timestamp of the file to the computer's current date and time, whatever that happens to be.

Here's an example that shows why we might want to do this. We wish to re-make a software project we are writing. We have changed the makefile and need to run make again. However, if we run make immediately we find that # make make: nothing to be done for `all'

Since the source code file is already updated, we will need to use touch to simulate a file update, so make will run and recompile the software. # touch project.c # makeThen make succeeds.

Here's how to change the date and time of a file.

# touch -t 200701310846.26 index.html # touch -d '2007-01-31 8:46:26' index.html # touch -d 'Jan 31 2007 8:46:26' index.html

The above three are equivalent: they will change the date and time of index.html to January 31, 2007 at 8:46:26am.

Although commands like cp, grep, chmod etc have a recursive switch (-r or -R or both) to apply the command recursively to the subdirectories, touch doesn't have this functionality yet (as of August, 2008). It can be accomplished by the following:

# find . -exec touch {} ;

This method is relatively slow. The faster method will be:

# find . | xargs touch

If the file names or subdirectory names contain spaces, the following should be used:

# find . -print0 | xargs -0 touch

Other operating systems

Programs that perform similar operations as the Unix touch utility are available for other operating systems, including Microsoft Windows and Mac OS.

ee also

*System time
*List of Unix programs

External links

* [http://www.opengroup.org/onlinepubs/009695399/utilities/touch.html touch specification from the Single Unix Specification]
* [http://www.flos-freeware.ch/archive.html The ntouch/dtouch page]
* [http://www.bellevuelinux.org/touch.html examples showing how to use touch]

Manual pages

* [http://www.gnu.org/software/coreutils/manual/html_node/touch-invocation.html touch] — manual page from GNU coreutils
* [http://www.openbsd.org/cgi-bin/man.cgi?query=touch touch] — manual page from OpenBSD


Wikimedia Foundation. 2010.

Игры ⚽ Нужна курсовая?

Look at other dictionaries:

  • Touch (Unix) — touch est une commande Unix standard permettant de modifier le timestamp de dernier accès et de dernière modification d un fichier. Cette commande permet également de créer un fichier vide. Historique Un utilitaire dénommé touch est apparu dans… …   Wikipédia en Français

  • Touch (Unix) — touch ist ein Unix Kommandozeilenprogramm zur Änderung der Zugriffs und Änderungszeitstempel einer Datei oder eines Verzeichnisses. Es ist ein Standardprogramm Unix ähnlicher Betriebssysteme nach POSIX Standard, das in Version 7 von AT Ts UNIX… …   Deutsch Wikipedia

  • touch (Unix) — touch ist ein Unix Kommandozeilenprogramm zur Änderung der Zugriffs und Änderungszeitstempel einer Datei oder eines Verzeichnisses. Es ist ein Standardprogramm Unix ähnlicher Betriebssysteme nach POSIX Standard, das in Version 7 von AT Ts UNIX… …   Deutsch Wikipedia

  • touch (Unix) — Pour les articles homonymes, voir Touch. touch est une commande Unix standard permettant de modifier le timestamp de dernier accès et de dernière modification d un fichier. Cette commande permet également de créer un fichier vide. Historique Un… …   Wikipédia en Français

  • Touch (Unix) — Para otros usos de este término, véase Touch. Touch es un programa de sistemas Unix utilizado para cambiar la fecha y hora de última modificación de un fichero. También puede utilizarse para crear un fichero vacío. Su sintaxis en línea de… …   Wikipedia Español

  • Touch — (englisch: berühren, anrühren, anfassen) hat die Bedeutung im Sprachgebrauch, dass jemand oder eine Sache angedeutet wird und ist die Bezeichnung für: The Touch (Band), eine deutsche Band Touch (Band), eine US amerikanische Band Touch (Album),… …   Deutsch Wikipedia

  • Touch — puede hacer referencia a: Touch (manga), un cómic de Mitsuru Adachi. Touch (Unix), un programa de sistemas Unix. Touch (onomatopeya) Touch, álbum de la banda Eurythmics. Touch, álbum de Laura Branigan. Touch, río francés afluente del Garona …   Wikipedia Español

  • Touch (disambiguation) — For the sense of touch, see:* Somatosensory system, for the neurophysiological basis of touch * Haptic perception, for the ability to recognize objects through touch * Haptic communication, for the study of human touching behaviour * Haptic… …   Wikipedia

  • Touch — touch  команда Unix, предназначенная для установки времени последнего изменения файла или доступа в текущее время. Также используется для создания пустых файлов. Содержание 1 История 2 Спецификация 3 …   Википедия

  • Unix — (officially trademarked as UNIX, sometimes also written as Unix with small caps) is a computer operating system originally developed in 1969 by a group of AT T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Douglas McIlroy, and… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”