Revision as of 12:06, 6 August 2017 edit2.25.45.251 (talk) Undid revision 792831737 by Winhunter (talk)Tag: Non-autoconfirmed user rapidly reverting edits← Previous edit | Revision as of 12:02, 31 August 2017 edit undoSmuckola (talk | contribs)Extended confirmed users, Pending changes reviewers, Rollbackers30,633 editsm deleting stuff that's literally WP:NOTMANUAL WP:NOTHOWTONext edit → | ||
Line 3: | Line 3: | ||
'''touch''' is a standard ] ] ] which is used to update the access date and or modification date of a ] 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 avoids opening, saving, and closing the file. 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 ] utilities or the ] 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. | '''touch''' is a standard ] ] ] which is used to update the access date and or modification date of a ] 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 avoids opening, saving, and closing the file. 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 ] utilities or the ] 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. | ||
== |
== Overview == | ||
A touch utility appeared in Version 7 AT&T UNIX. The version of <tt>touch</tt> bundled in ] ] was written by Paul Rubin, Arnold Robbins, Jim Kingdon, and David MacKenzie. | A touch utility appeared in Version 7 AT&T UNIX. The version of <tt>touch</tt> bundled in ] ] was written by Paul Rubin, Arnold Robbins, Jim Kingdon, and David MacKenzie. | ||
== Specification == | |||
The ] (SUS) specifies that <tt>touch</tt> 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, <tt>touch</tt> uses the current time. | The ] (SUS) specifies that <tt>touch</tt> 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, <tt>touch</tt> uses the current time. | ||
== Usage == | |||
The SUS mandates the following options: | |||
: <tt>-a</tt>, change the access time only | |||
: <tt>-c</tt>, if the file does not exist, do not create it and do not report this condition | |||
: <tt>-d ''date_time''</tt>, use the date_time specified to update the access and modification times | |||
: <tt>-m</tt>, change the modification time only | |||
: <tt>-r ''file''</tt>, use the access and modification times of <tt>''file''</tt> | |||
: <tt>-t ''time''</tt>, use the time specified (in the format below) to update the access and modification times | |||
The time is specified in the format <nowiki>yy]MMDDhhmm</nowiki> 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 ] operating systems may add extra options. For example, GNU <tt>touch</tt> adds a <tt>-d</tt> option, which enables time input in formats other than that specified. | |||
Note that the dates of creation of symbolic links are not changed. | |||
== Examples == | |||
The simplest ] for touch is this: | |||
<source lang="bash"> | |||
$ touch myfile.txt | |||
</source> | |||
Touch does not modify the contents of myfile.txt; it just updates the ] of the file to the computer's current date and time. Or, if myfile.txt does not exist it is created, with zero length. | |||
An example of why it might be desired to do this would be a software project needs to be recompiled with ]. The makefile has been changed and <tt>make</tt> needs to be run again. However, if make is run immediately it will return: | |||
<source lang="console"> | |||
$ make | |||
make: nothing to be done for `all' | |||
</source> | |||
Since the source code file is already updated, touch can be used to simulate a file update, so <tt>make</tt> will run and recompile the software. | |||
<source lang="bash"> | |||
$ touch project.c | |||
$ make | |||
</source> | |||
Then make will rebuild the project. | |||
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 25th Jan 2012 – it has not changed to the 20th Feb 2012. | |||
<source lang="console"> | |||
$ date | |||
Wed Feb 20 09:45:50 GMT 2012 | |||
$ ls -l libcidn.so | |||
lrwxrwxrwx 1 foobar foobar 22 Jan 25 01:41 libcidn.so -> ../../lib/libcidn.so.1 | |||
$ touch libcidn.so | |||
$ ls -l libcidn.so | |||
lrwxrwxrwx 1 foobar foobar 22 Jan 25 01:41 libcidn.so -> ../../lib/libcidn.so.1 | |||
</source> | |||
<code>touch</code> is not able to act recursively. | |||
== Other operating systems == | |||
Programs that perform similar operations as the Unix <code>touch</code> utility are available for other operating systems, including ] and the ].{{which|date=January 2015 <!-- a short list here would be very useful -->}} | Programs that perform similar operations as the Unix <code>touch</code> utility are available for other operating systems, including ] and the ].{{which|date=January 2015 <!-- a short list here would be very useful -->}} |
Revision as of 12:02, 31 August 2017
This article is written like a manual or guide. Please help rewrite this article and remove advice or instruction. (May 2014) |
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 avoids opening, saving, and closing the file. 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.
Overview
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.
Programs that perform similar operations as the Unix touch
utility are available for other operating systems, including Microsoft Windows and the classic Mac OS.
See also
External links
touch
– Shell and Utilities Reference, The Single UNIX Specification, Version 4 from The Open Group- examples showing how to use touch
- touch for Windows
Unix command-line interface programs and shell builtins | |
---|---|
File system | |
Processes | |
User environment | |
Text processing | |
Shell builtins | |
Searching | |
Documentation | |
Software development | |
Miscellaneous | |
|
Categories: