Linux--Touch

Source: Internet
Author: User
Tags time zones

/usr/share/info/coreutils.info.gz
File:coreutils.info, Node:touch invocation, prev:chmod invocation, up:changing file attributes

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 this does not exist is created empty, unless
Option '--no-create ' ('-c ') or '--no-dereference ' ('-h ') is in effect.

A FILE argument string of '-' is handled specially and causes
' Touch ' to change the times of the the file associated with standard output.

By default, ' Touch ' sets file timestamps to the current time.
Because ' touch ' acts on it operands left to right, the resulting
Timestamps of earlier and later operands may disagree. Also, the
Determination of "current" depends on the platform.
Platforms with network file systems often use different clocks for the
Operating system and for file systems; Because ' touch ' typically uses
File Systems ' clocks by default, clock skew can cause the resulting
File timestamps to appear to is in a program's "future" or "past".

The ' Touch ' command sets the file ' s timestamp to the greatest
Representable value is not greater than the requested time. This
Can differ from the requested time for several reasons. First, the
Requested time may have a higher resolution than supported. Second, a
File system different resolutions for different types of times.
Third, file timestamps may use a different resolution than operating
System timestamps. Fourth, the operating system primitives used to
Update timestamps may employ yet a different resolution. For example,
In theory a file system might with 10-microsecond resolution for access
Time and 100-nanosecond resolution for modification time, and the
Operating system might use nanosecond resolution for the current time
and microsecond resolution for the primitive this ' touch ' uses to set a
File ' s timestamp to an arbitrary value.

When setting file timestamps to the current time, ' touch ' can change
The timestamps for files, the user does not own but have write
Permission for.  Otherwise, the user must own the files. Some older
Systems have a further restriction:the user must own the files unless
Both the access and modification times is being set to the current
Time.

Although ' touch ' provides options for changing of the times--the
Times of last access and modification--of a file, there is actually a
Standard 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 while 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. Yet, something
About the file itself have changed, and this must is noted somewhere.
This is the job of the CTime field. This is necessary
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's not
Possible, in normal operations, for a user to change the CTime field to
A user-specified value. Some operating systems and file systems
Support a fourth time:the birth time, when the file is first created;
By definition, this timestamp never changes.

Time stamps assume the time zone rules specified by the ' TZ '
environment variable, or by the system default rules if ' TZ ' is not
Set.  *note specifying the time Zone with ' TZ ': (libc) TZ Variable. You
Can avoid ambiguities during daylight saving transitions by using UTC
Time stamps.

The program accepts the following options. Also See *note Common
Options::.

(a) To modify the time type, no option defaults to the creation time
'-A '
'--time=atime '
'--time=access '
'--time=use '
Change the access time only.


'-M '
'--time=mtime '
'--time=modify '
Change the modification time only.

(b) Select the time to modify, without the option to default the current time

1. Precise selection of time
'-t [[cc]yy]mmddhhmm[. SS] ' [year] [month] [day] [TIME] [minute] [sec]
Use the argument (optional Four-digit or two-digit years, months,
Days, hours, minutes, optional seconds) instead of the current
Time. If the year was specified with only a digits, then CC is
Years in the range 0 ... Years in 69 ... 99.
If no digits of the year was specified, the argument is
interpreted as a date in the current year. On the atypical
Systems, support for leap seconds, SS May is ' 60 '.

'-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's 489,392,193 nanoseconds after February 27,
2004 at 2:19:13 PM in a time zone this is 5 hours and minutes
East of UTC.  *note Date input formats::. File Systems
High-resolution time stamps silently ignore any excess
Precision here.
The above two options can create a future file

2, refer to a file selection time
'-R FILE '
'--reference=file '
Use the Times of the reference FILE instead of the current time.
If This option was combined with the '--date=time ' ('-D time ')
option, the reference FILE ' s time is the origin of 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 '. If FILE is a symbolic
Link, the reference timestamp is taken from the target of the
Symlink, unless '-H ' is also in effect.

(iii) processing of linked documents
'-H '
'--no-dereference '
Attempt to change the timestamps of a symbolic link, rather than
What's the link refers to. When using the This option, empty files is
Not created, but option '-C ' must also be used to avoid warning
About the files that does not exist. Not all systems support changing
The timestamps of symlinks, since underlying system support for
This action is not required until POSIX 2008. Also, on some
Systems, the mere act of examining a symbolic link changes the
Access time, such that is changes to the modification time would
Persist long enough to be observable. When coupled with option
'-R ', a reference timestamp is taken from a symbolic link rather
than the file it refers to.

'-C '
'--no-create '
Do not warn about or create files, that does not exist.

'-F '
ignored; For compatibility with BSD versions of ' Touch '.
On older systems, the ' touch ' supports an obsolete syntax, as follows.
If no timestamp is given with any of the '-d ', '-R ', or '-t ' options,
And if there is, or more FILEs and the first FILE is of the form
' Mmddhhmm[yy] ' and this would is a valid argument to the '-t ' option
(If the YY, if any, were moved to the front), and if the represented
Year are in the range 1969-1999, which argument is interpreted as the time
For the other files instead of as a file name. This obsolete behavior
Can is enabled or disabled with the ' _posix2_version ' environment
Variable (*note 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.


Linux--Touch

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.