📄 ch21_05.htm
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 21] 21.5 What Good Is a File's Last Access Time? </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly & Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly & Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:40:04Z"><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_04.htm"TITLE="21.4 Why Both /tmp and /usr/tmp? "><LINKREL="next"HREF="ch21_06.htm"TITLE="21.6 A File's Inode Change (not "Creation"!) Time"></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_04.htm"TITLE="21.4 Why Both /tmp and /usr/tmp? "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 21.4 Why Both /tmp and /usr/tmp? "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_06.htm"TITLE="21.6 A File's Inode Change (not "Creation"!) Time"><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 21.6 A File's Inode Change (not "Creation"!) Time"BORDER="0"></A></TD></TR></TABLE> <HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-0116">21.5 What Good Is a File's Last Access Time? </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-23124"></A><ACLASS="indexterm"NAME="AUTOID-23126"></A><ACLASS="indexterm"NAME="AUTOID-23129"></A><ACLASS="indexterm"NAME="AUTOID-23132"></A>UNIX keeps three times for each file: last modification, last inode change,and last access.Here are some things you can do with the last-access time:</P><ULCLASS="itemizedlist"><LICLASS="listitem"><PCLASS="para">Find files that have been forgotten.This information comes from commands like<SPANCLASS="link"><EMCLASS="emphasis">ls -lu</EM> (<ACLASS="linkend"HREF="ch16_02.htm"TITLE="Finding Oldest or Newest Files with ls -t and ls -u ">16.2</A>)</SPAN>and<SPANCLASS="link"><EMCLASS="emphasis">find -atime +180</EM> (<ACLASS="linkend"HREF="ch17_05.htm"TITLE="Searching for Old Files ">17.5</A>)</SPAN>.(If you use the MH email system, you can find mail messages that haven'tbeen read or scanned in a long time.)You can save disk space by cleaning up unused files; see article<ACLASS="xref"HREF="ch23_19.htm"TITLE="Deleting (BSD) Manual Pages that Aren't Read ">23.19</A>.</P></LI><LICLASS="listitem"><PCLASS="para">Automatically<SPANCLASS="link"><EMCLASS="emphasis">gzip</EM> (<ACLASS="linkend"HREF="ch24_07.htm"TITLE="Compressing Files to Save Space ">24.7</A>)</SPAN>files to save disk space.<ACLASS="indexterm"NAME="AUTOID-23148"></A>Some users run a shell script named <EMCLASS="emphasis">compresser</EM>, which looks fornonexecutable files that haven't been accessed in 90 days.The program runs <EMCLASS="emphasis">gzip</EM> on these files:</P><PCLASS="para"><TABLECLASS="screen.co"BORDER="1"><TR><THVALIGN="TOP"><PRECLASS="calloutlist"><ACLASS="co"HREF="ch17_15.htm"TITLE="17.15 Searching for Files by Permission ">-perm -100</A> <ACLASS="co"HREF="ch09_21.htm"TITLE="9.21 Handle Too-Long Command Lines with xargs ">xargs</A> </PRE></TH><TDVALIGN="TOP"><PRECLASS="screen">find <CODECLASS="replaceable"><I>dir1 dir2</I></CODE> -type f ! -name '*.gz' ! -perm -100 -atime +90 -print | \ xargs gzip -v</PRE></TD></TR></TABLE></P><PCLASS="para">A system like this could automatically archive files to tape and delete them.It could have a personal "skip" list of files and directories to skip.And so on... </P></LI><LICLASS="listitem"><PCLASS="para">Check a directory to see which files are being read by programs,compilers, etc.This "sanity check" can help you debug programs by confirming which files arebeing accessed.</P></LI></UL><BLOCKQUOTECLASS="note"><PCLASS="para"><STRONG>NOTE:</STRONG> Some UNIX systems, including versions of BSD and SunOS, do not updatethe access time of executable files (programs) when they're executed.To test yours, use <EMCLASS="emphasis">ls -lu</EM> on a pure-executable file (not a shellscript) before and after you run it.</P></BLOCKQUOTE><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <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_04.htm"TITLE="21.4 Why Both /tmp and /usr/tmp? "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 21.4 Why Both /tmp and /usr/tmp? "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_06.htm"TITLE="21.6 A File's Inode Change (not "Creation"!) Time"><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 21.6 A File's Inode Change (not "Creation"!) Time"BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">21.4 Why Both /tmp and /usr/tmp? </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.6 A File's Inode Change (not "Creation"!) Time</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 & 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 + -