World Library  
Flag as Inappropriate
Email this Article

Touch (Unix)

Article Id: WHEBN0000431972
Reproduction Date:

Title: Touch (Unix)  
Author: World Heritage Encyclopedia
Language: English
Subject: Stand-alone shell, Touch (disambiguation), List of Inferno applications, Whereis, Apropos (Unix)
Collection: Standard Unix Programs, Unix Sus2008 Utilities
Publisher: World Heritage Encyclopedia

Touch (Unix)

touch is a standard Unix command-line interface program which is used to update the access date and / or modification date of a file or directory. In its default usage, it is the equivalent of creating or opening a file and saving it without any change to the file contents. Touch eliminates the unnecessary steps of opening the file, saving the file, and closing the file again. Instead it simply updates the dates associated with the file or directory. An updated access or modification date can be important for a variety of other programs such as backup utilities or the make command-line interface programming utility. Typically these types of programs are only concerned with files which have been created or modified after the program was last run. Touch can also be useful for quickly creating files for programs or scripts that require a file with a specific name to exist for successful operation of the program, but do not require the file to have any specific content.


  • History 1
  • Specification 2
  • Usage 3
  • Examples 4
  • Other operating systems 5
  • See also 6
  • External links 7


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, and David MacKenzie.


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.


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
-d date_time, use the date_time specified to update the access and modification times
-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.

Note that the dates of creation of symbolic links are not changed .


The simplest use case for touch is this:

 $ touch myfile.txt

Touch 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. Or, if myfile.txt does not exist it is created, with zero length.

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
 $ make

Then make will rebuild the project.

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

 $ touch -t 200701310846.26 index.html
 $ touch -d '2007-01-31 08:46:26' index.html

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

The creation date of links are unchanged. For example, on the following system, the date is the 20th Feb 2012, but a link was created on 25th Jan 2012. Despite touching the link, the date remains as 22nd Jan 2012 – it has not changed to the 20th Feb 2012.

$ date
Wed Feb 20 09:45:50 GMT 2012
$ ls -l
lrwxrwxrwx  1 foobar foobar 22 Jan 25 01:41 -> ../../lib/
$ touch
$ ls -l
lrwxrwxrwx  1 foobar foobar 22 Jan 25 01:41 -> ../../lib/

Although commands like cp, 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 February, 2013). It can be accomplished by the following:

 $ find . -exec 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.

See also

External links

This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.

Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.