⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch21_07.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 21] 21.7 Setting File Modification Time with touch </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly &amp; Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:40:06Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch21_01.htm"TITLE="21. More About Managing Files"><LINKREL="prev"HREF="ch21_06.htm"TITLE="21.6 A File's Inode Change (not  &#34;Creation&quot;!) Time"><LINKREL="next"HREF="ch21_08.htm"TITLE="21.8 The MAILCHECK and mail Variables Check More than Mail"></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch21_06.htm"TITLE="21.6 A File's Inode Change (not  &#34;Creation&quot;!) Time"><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 21.6 A File's Inode Change (not  &#34;Creation&quot;!) Time"BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 21<BR>More About Managing Files</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch21_08.htm"TITLE="21.8 The MAILCHECK and mail Variables Check More than Mail"><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 21.8 The MAILCHECK and mail Variables Check More than Mail"BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-7810">21.7 Setting File Modification Time with touch </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-23199"></A><ACLASS="indexterm"NAME="AUTOID-23202"></A><ACLASS="indexterm"NAME="AUTOID-23204"></A><ACLASS="indexterm"NAME="AUTOID-23207"></A><ACLASS="indexterm"NAME="AUTOID-23210"></A><ACLASS="indexterm"NAME="AUTOID-23212"></A><ACLASS="indexterm"NAME="AUTOID-23215"></A>How can you make a file quickly (often for some kind of test)?In the Bourne shell, use the command below.Because this command uses a<SPANCLASS="link">built-in (<ACLASS="linkend"HREF="ch01_10.htm"TITLE="Internal and External Commands ">1.10</A>)</SPAN>operator, it's fast and efficient.This creates a new file or empties an existing file:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">$ <CODECLASS="userinput"><B>&gt; </B></CODE><CODECLASS="replaceable"><I>filename</I></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">The C shell doesn't allow that.From the C shell, you can empty a file by<SPANCLASS="link">copying <EMCLASS="emphasis">/dev/null</EM> onto it (<ACLASS="linkend"HREF="ch24_01.htm#UPT-ART-1730"TITLE="Instead of Removing a File, Empty It ">24.1</A>)</SPAN>.The easiest way to create an empty file is with the <EMCLASS="emphasis">touch</EM> command.<EMCLASS="emphasis">touch</EM> is also useful from any shell to change an existingfile's modification time to &quot;now&quot;-without changingthe file's contents (usually for an automatic<SPANCLASS="link">file time comparison (<ACLASS="linkend"HREF="ch17_08.htm"TITLE="Exact File Time Comparisons ">17.8</A>, <ACLASS="linkend"HREF="ch28_13.htm"TITLE="make Isn't Just for Programmers! ">28.13</A>, <ACLASS="linkend"HREF="ch21_09.htm"TITLE="Keep File Printouts Up-to-Date Automatically with make">21.9</A>)</SPAN>).You can touch more than one file at a time.Just type:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>touch </B></CODE><CODECLASS="replaceable"><I>filename1 filename2</I></CODE><CODECLASS="userinput"><B> ...</B></CODE></PRE></BLOCKQUOTE></P><TABLECLASS="para.programreference"BORDER="1"><TR><THVALIGN="TOP"><ACLASS="programreference"HREF="examples/index.htm"TITLE="touch">touch</A><BR></TH><TDVALIGN="TOP">&#13;Some versions of <EMCLASS="emphasis">touch</EM> (including the GNU version onthe CD-ROM)can create a file with an arbitrary timestamp.That is, you can use <EMCLASS="emphasis">touch</EM> to make a file that's backdated toany point in the past (or, for that matter, postdated to some pointin the future).If your version can do that, the syntax is probably like:</TD></TR></TABLE><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>touch</B></CODE> <CODECLASS="replaceable"><I>date filename1 filename2</I></CODE><CODECLASS="userinput"><B> ...</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">&#13;where <CODECLASS="replaceable"><I>date</I></CODE> has the form:</P><BLOCKQUOTECLASS="blockquote"><PCLASS="para"><CODECLASS="replaceable"><I>modyhrmiyy</I></CODE></P></BLOCKQUOTE><PCLASS="para">and:&#13;</P><DLCLASS="variablelist"><DTCLASS="term"><CODECLASS="replaceable"><I>mo</I></CODE></DT><DDCLASS="listitem"><PCLASS="para">is two digits, representing the month. </P></DD><DTCLASS="term"><CODECLASS="replaceable"><I>dy</I></CODE></DT><DDCLASS="listitem"><PCLASS="para">is two digits, representing the day of the month.</P></DD><DTCLASS="term"><CODECLASS="replaceable"><I>hr</I></CODE></DT><DDCLASS="listitem"><PCLASS="para">is two digits, representing the hour (on a 24-hour clock).</P></DD><DTCLASS="term"><CODECLASS="replaceable"><I>mi</I></CODE></DT><DDCLASS="listitem"><PCLASS="para">is two digits, representing the minute within the hour.</P></DD><DTCLASS="term"><CODECLASS="replaceable"><I>yy</I></CODE></DT><DDCLASS="listitem"><PCLASS="para">is two digits, representing the year (within the twentieth century).These two digits are optional; if you omit them, <EMCLASS="emphasis">date</EM> assumesthe current year.&#13;</P></DD></DL><PCLASS="para">For example, to create a file dated 4&nbsp;p.m., March&nbsp;20 of this year, give thecommand:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>touch 03201600 foo</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">If you don't want to use a different timestamp (that is, you want thecurrent time) and the filename starts with a digit, <EMCLASS="emphasis">touch</EM> mightthink that the filename is a time and complain &quot;date: bad conversion.&quot;To start a filename with a digit, use a relative pathname that startswith a<SPANCLASS="link"><CODECLASS="literal">.</CODE> (dot) (<ACLASS="linkend"HREF="ch01_21.htm"TITLE="Making Pathnames ">1.21</A>)</SPAN>.For example, to make a file<EMCLASS="emphasis">123456</EM> in the current directory:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>touch ./123456</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">Article<ACLASS="xref"HREF="ch22_16.htm"TITLE="Copying Permissions with cpmod ">22.16</A>explains <EMCLASS="emphasis">cpmod</EM>, a program on the CD-ROM for copyingdates and permissions from file to file.</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">ML</SPAN>, <SPANCLASS="authorinitials">JP</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch21_06.htm"TITLE="21.6 A File's Inode Change (not  &#34;Creation&quot;!) Time"><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 21.6 A File's Inode Change (not  &#34;Creation&quot;!) Time"BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch21_08.htm"TITLE="21.8 The MAILCHECK and mail Variables Check More than Mail"><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 21.8 The MAILCHECK and mail Variables Check More than Mail"BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">21.6 A File's Inode Change (not  "Creation&quot;!) Time</TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">21.8 The MAILCHECK and mail Variables Check More than Mail</TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed &amp; awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -