📄 ch17_01.htm
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 17] Finding Files with find</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:38:13Z"><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="part03.htm"TITLE="III. Working with the Filesystem "><LINKREL="prev"HREF="ch16_29.htm"TITLE="16.29 sls: Super ls with Format You Can Choose "><LINKREL="next"HREF="ch17_02.htm"TITLE="17.2 Delving Through a Deep Directory Tree "></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="ch16_29.htm"TITLE="16.29 sls: Super ls with Format You Can Choose "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 16.29 sls: Super ls with Format You Can Choose "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 17</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch17_02.htm"TITLE="17.2 Delving Through a Deep Directory Tree "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 17.2 Delving Through a Deep Directory Tree "BORDER="0"></A></TD></TR></TABLE> <HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="CHAPTER"><H1CLASS="chapter"><ACLASS="title"NAME="UPT-CHP-17">17. Finding Files with find</A></H1><DIVCLASS="htmltoc"><P><B>Contents:</B><BR><ACLASS="sect1"HREF="#UPT-ART-7410"TITLE="17.1 The find Command Is Great; The Problem Is Finding How to Use It">The find Command Is Great; The Problem Is Finding How to Use It</A><BR><ACLASS="sect1"HREF="ch17_02.htm"TITLE="17.2 Delving Through a Deep Directory Tree ">Delving Through a Deep Directory Tree </A><BR><ACLASS="sect1"HREF="ch17_03.htm"TITLE="17.3 Don't Forget -print ">Don't Forget -print </A><BR><ACLASS="sect1"HREF="ch17_04.htm"TITLE="17.4 Looking for Files with Particular Names ">Looking for Files with Particular Names </A><BR><ACLASS="sect1"HREF="ch17_05.htm"TITLE="17.5 Searching for Old Files ">Searching for Old Files </A><BR><ACLASS="sect1"HREF="ch17_06.htm"TITLE="17.6 Be an Expert on find Search Operators ">Be an Expert on find Search Operators </A><BR><ACLASS="sect1"HREF="ch17_07.htm"TITLE="17.7 The Times that find Finds ">The Times that find Finds </A><BR><ACLASS="sect1"HREF="ch17_08.htm"TITLE="17.8 Exact File Time Comparisons ">Exact File Time Comparisons </A><BR><ACLASS="sect1"HREF="ch17_09.htm"TITLE="17.9 Problems with -newer ">Problems with -newer </A><BR><ACLASS="sect1"HREF="ch17_10.htm"TITLE="17.10 Running Commands on What You Find ">Running Commands on What You Find </A><BR><ACLASS="sect1"HREF="ch17_11.htm"TITLE="17.11 Using -exec to Create Custom Tests ">Using -exec to Create Custom Tests </A><BR><ACLASS="sect1"HREF="ch17_12.htm"TITLE="17.12 Finding Many Things with One Command ">Finding Many Things with One Command </A><BR><ACLASS="sect1"HREF="ch17_13.htm"TITLE="17.13 Searching for Files by Type ">Searching for Files by Type </A><BR><ACLASS="sect1"HREF="ch17_14.htm"TITLE="17.14 Searching for Files by Size ">Searching for Files by Size </A><BR><ACLASS="sect1"HREF="ch17_15.htm"TITLE="17.15 Searching for Files by Permission ">Searching for Files by Permission </A><BR><ACLASS="sect1"HREF="ch17_16.htm"TITLE="17.16 Searching by Owner and Group ">Searching by Owner and Group </A><BR><ACLASS="sect1"HREF="ch17_17.htm"TITLE="17.17 Duplicating a Directory Tree (No Pathnames with find {} Operator)">Duplicating a Directory Tree (No Pathnames with find {} Operator)</A><BR><ACLASS="sect1"HREF="ch17_18.htm"TITLE='17.18 Using "Fast find"'>Using "Fast find"</A><BR><ACLASS="sect1"HREF="ch17_19.htm"TITLE="17.19 Finding Files (Much) Faster with a find Database ">Finding Files (Much) Faster with a find Database </A><BR><ACLASS="sect1"HREF="ch17_20.htm"TITLE="17.20 grepping a Directory Tree (and a Gotcha) ">grepping a Directory Tree (and a Gotcha) </A><BR><ACLASS="sect1"HREF="ch17_21.htm"TITLE="17.21 lookfor: Which File Has that Word? ">lookfor: Which File Has that Word? </A><BR><ACLASS="sect1"HREF="ch17_22.htm"TITLE="17.22 Finding the Links to a File ">Finding the Links to a File </A><BR><ACLASS="sect1"HREF="ch17_23.htm"TITLE="17.23 Finding Files with -prune ">Finding Files with -prune </A><BR><ACLASS="sect1"HREF="ch17_24.htm"TITLE="17.24 Skipping Some Parts of a Tree in find (A More Selective -prune)">Skipping Some Parts of a Tree in find (A More Selective -prune)</A><BR><ACLASS="sect1"HREF="ch17_25.htm"TITLE="17.25 Keeping find From Searching Networked Filesystems">Keeping find From Searching Networked Filesystems</A></P><P></P></DIV><DIVCLASS="sect1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-7410">17.1 The find Command Is Great; The Problem Is Finding How to Use It</A></H2><PCLASS="para"><ACLASS="indexterm"NAME="UPT-ART-7410-IX-FIND-COMMAND"></A><ACLASS="indexterm"NAME="AUTOID-18089"></A><EMCLASS="emphasis">find</EM> is one of UNIX's most useful and important utilities. Itfinds files that match a given set of parameters, ranging from thefile's name to its modification date. In this chapter, we'll belooking at many of the things it can do. As an introduction, here's aquick summary of its features and operators:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>find </B></CODE><CODECLASS="replaceable"><I>path operators</I></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">where <CODECLASS="replaceable"><I>path</I></CODE> is the directory in which <EMCLASS="emphasis">find</EM> will begin tosearch and <CODECLASS="replaceable"><I>operators</I></CODE> (or, in more customary jargon,<EMCLASS="emphasis">options</EM>) tell <EMCLASS="emphasis">find</EM> which files you're interested in. The<CODECLASS="replaceable"><I>operators</I></CODE> are: </P><DLCLASS="variablelist"><DTCLASS="term"><CODECLASS="literal">-name</CODE> <CODECLASS="replaceable"><I>filename</I></CODE></DT><DDCLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-18111"></A>Find files with the given <CODECLASS="replaceable"><I>filename</I></CODE>. Thisis the most commonly used operator. <CODECLASS="replaceable"><I>filename</I></CODE> may include<SPANCLASS="link">wildcards (<ACLASS="linkend"HREF="ch15_02.htm"TITLE="Filename Wildcards in a Nutshell ">15.2</A>)</SPAN>,but if it does, it must be quoted to prevent the shellfrom interpreting the wildcards.See article<ACLASS="xref"HREF="ch17_04.htm"TITLE="Looking for Files with Particular Names ">17.4</A>.</P></DD><DTCLASS="term"><CODECLASS="literal">-perm</CODE> <CODECLASS="replaceable"><I>mode</I></CODE></DT><DDCLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-18124"></A>Find files with the given<SPANCLASS="link">access <CODECLASS="replaceable"><I>mode</I></CODE> (<ACLASS="linkend"HREF="ch22_02.htm"TITLE="Tutorial on File and Directory Permissions ">22.2</A>)</SPAN>.You must give the access mode in<SPANCLASS="link">octal (<ACLASS="linkend"HREF="ch01_23.htm"TITLE="File Access Permissions ">1.23</A>)</SPAN>.See articles<ACLASS="xref"HREF="ch17_10.htm"TITLE="Running Commands on What You Find ">17.10</A>and<ACLASS="xref"HREF="ch17_15.htm"TITLE="Searching for Files by Permission ">17.15</A>.</P></DD><DTCLASS="term"><CODECLASS="literal">-type</CODE> <CODECLASS="replaceable"><I>c</I></CODE></DT><DDCLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-18138"></A>The files of the given type, specified by <CODECLASS="replaceable"><I>c</I></CODE>.<CODECLASS="replaceable"><I>c</I></CODE> is a one-digit code; for example, <CODECLASS="literal">f</CODE> for a plain file,<CODECLASS="literal">b</CODE> for a block special file, <CODECLASS="literal">l</CODE> for a symbolic link, etc.See article<ACLASS="xref"HREF="ch17_13.htm"TITLE="Searching for Files by Type ">17.13</A>.</P></DD><DTCLASS="term"><CODECLASS="literal">-user</CODE> <CODECLASS="replaceable"><I>name</I></CODE></DT><DDCLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-18153"></A>Find files belonging to user <CODECLASS="replaceable"><I>name</I></CODE>. <CODECLASS="replaceable"><I>name</I></CODE> may also be a<SPANCLASS="link">user ID number (<ACLASS="linkend"HREF="ch38_03.htm"TITLE="Managing Processes: Overall Concepts ">38.3</A>)</SPAN>.See article<ACLASS="xref"HREF="ch17_16.htm"TITLE="Searching by Owner and Group ">17.16</A>.</P></DD><DTCLASS="term"><CODECLASS="literal">-group</CODE> <CODECLASS="replaceable"><I>name</I></CODE></DT><DDCLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-18165"></A>Find files belonging to group <CODECLASS="replaceable"><I>name</I></CODE>. <CODECLASS="replaceable"><I>name</I></CODE> may also be a<SPANCLASS="link">group ID number (<ACLASS="linkend"HREF="ch38_03.htm"TITLE="Managing Processes: Overall Concepts ">38.3</A>)</SPAN>.See article<ACLASS="xref"HREF="ch17_16.htm"TITLE="Searching by Owner and Group ">17.16</A>.</P></DD><DTCLASS="term"><CODECLASS="literal">-size</CODE> <CODECLASS="replaceable"><I>n</I></CODE></DT><DDCLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-18178"></A>Find files that are <CODECLASS="replaceable"><I>n</I></CODE> blocks long. A blockequals 512 bytes. The notation <CODECLASS="literal">+</CODE><CODECLASS="replaceable"><I>n</I></CODE> says "find files that areover <CODECLASS="replaceable"><I>n</I></CODE> blocks long." The notation <CODECLASS="replaceable"><I>n</I></CODE><CODECLASS="literal">c</CODE> says "find filesthat are <CODECLASS="replaceable"><I>n</I></CODE> characters long." Can you guess what <CODECLASS="literal">+</CODE><CODECLASS="replaceable"><I>n</I></CODE><CODECLASS="literal">c</CODE>means?See article<ACLASS="xref"HREF="ch17_14.htm"TITLE="Searching for Files by Size ">17.14</A>.</P></DD><DTCLASS="term"><CODECLASS="literal">-inum</CODE> <CODECLASS="replaceable"><I>n</I></CODE></DT><DDCLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-18198"></A>Find files with the <SPANCLASS="link">inode number (<ACLASS="linkend"HREF="ch01_22.htm"TITLE="How UNIX Keeps Track of Files: Inodes ">1.22</A>)</SPAN><CODECLASS="replaceable"><I>n</I></CODE>.See article<ACLASS="xref"HREF="ch17_10.htm"TITLE="Running Commands on What You Find ">17.10</A>.</P
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -