Files
oldlinux-files/study/Ref-docs/POSIX/susv3/utilities/find.html
2024-02-19 00:25:23 -05:00

686 lines
30 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
<title>find</title>
</head>
<body bgcolor="white">
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
</script>
<basefont size="3"> <a name="find"></a> <a name="tag_04_55"></a><!-- find -->
<!--header start-->
<center><font size="2">The Open Group Base Specifications Issue 6<br>
IEEE Std 1003.1-2001<br>
Copyright &copy; 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
<!--header end-->
<hr size="2" noshade>
<h4><a name="tag_04_55_01"></a>NAME</h4>
<blockquote>find - find files</blockquote>
<h4><a name="tag_04_55_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<p><code><tt>find</tt> <b>[</b><tt>-H | -L</tt><b>]</b> <i>path</i> <tt>...</tt> <b>[</b><i>operand_expression</i> <tt>...</tt><b>]</b>
</code></p>
</blockquote>
<h4><a name="tag_04_55_03"></a>DESCRIPTION</h4>
<blockquote>
<p>The <i>find</i> utility shall recursively descend the directory hierarchy from each file specified by <i>path</i>, evaluating a
Boolean expression composed of the primaries described in the OPERANDS section for each file encountered.</p>
<p>The <i>find</i> utility shall be able to descend to arbitrary depths in a file hierarchy and shall not fail due to path length
limitations (unless a <i>path</i> operand specified by the application exceeds {PATH_MAX} requirements).</p>
<p>The <i>find</i> utility shall detect infinite loops; that is, entering a previously visited directory that is an ancestor of the
last file encountered. When it detects an infinite loop, <i>find</i> shall write a diagnostic message to standard error and shall
either recover its position in the hierarchy or terminate.</p>
</blockquote>
<h4><a name="tag_04_55_04"></a>OPTIONS</h4>
<blockquote>
<p>The <i>find</i> utility shall conform to the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../basedefs/xbd_chap12.html#tag_12_02">Section 12.2, Utility Syntax Guidelines</a>.</p>
<p>The following options shall be supported by the implementation:</p>
<dl compact>
<dt><b>-H</b></dt>
<dd>Cause the file information and file type evaluated for each symbolic link encountered on the command line to be those of the
file referenced by the link, and not the link itself. If the referenced file does not exist, the file information and type shall be
for the link itself. File information for all symbolic links not on the command line shall be that of the link itself.</dd>
<dt><b>-L</b></dt>
<dd>Cause the file information and file type evaluated for each symbolic link to be those of the file referenced by the link, and
not the link itself.</dd>
</dl>
<p>Specifying more than one of the mutually-exclusive options <b>-H</b> and <b>-L</b> shall not be considered an error. The last
option specified shall determine the behavior of the utility.</p>
</blockquote>
<h4><a name="tag_04_55_05"></a>OPERANDS</h4>
<blockquote>
<p>The following operands shall be supported:</p>
<p>The <i>path</i> operand is a pathname of a starting point in the directory hierarchy.</p>
<p>The first argument that starts with a <tt>'-'</tt> , or is a <tt>'!'</tt> or a <tt>'('</tt> , and all subsequent arguments shall
be interpreted as an <i>expression</i> made up of the following primaries and operators. In the descriptions, wherever <i>n</i> is
used as a primary argument, it shall be interpreted as a decimal integer optionally preceded by a plus ( <tt>'+'</tt> ) or minus (
<tt>'-'</tt> ) sign, as follows:</p>
<dl compact>
<dt>+<i>n</i></dt>
<dd>More than <i>n</i>.</dd>
<dt><i>n</i></dt>
<dd>Exactly <i>n</i>.</dd>
<dt>-<i>n</i></dt>
<dd>Less than <i>n</i>.</dd>
</dl>
<p>The following primaries shall be supported:</p>
<dl compact>
<dt><b>-name&nbsp;</b> <i>pattern</i></dt>
<dd><br>
The primary shall evaluate as true if the basename of the filename being examined matches <i>pattern</i> using the pattern matching
notation described in <a href="xcu_chap02.html#tag_02_13"><i>Pattern Matching Notation</i></a> .</dd>
<dt><b>-nouser</b></dt>
<dd>The primary shall evaluate as true if the file belongs to a user ID for which the <a href=
"../functions/getpwuid.html"><i>getpwuid</i>()</a> function defined in the System Interfaces volume of
IEEE&nbsp;Std&nbsp;1003.1-2001 (or equivalent) returns NULL.</dd>
<dt><b>-nogroup</b></dt>
<dd>The primary shall evaluate as true if the file belongs to a group ID for which the <a href=
"../functions/getgrgid.html"><i>getgrgid</i>()</a> function defined in the System Interfaces volume of
IEEE&nbsp;Std&nbsp;1003.1-2001 (or equivalent) returns NULL.</dd>
<dt><b>-xdev</b></dt>
<dd>The primary shall always evaluate as true; it shall cause <i>find</i> not to continue descending past directories that have a
different device ID ( <i>st_dev</i>, see the <a href="../functions/stat.html"><i>stat</i>()</a> function defined in the System
Interfaces volume of IEEE&nbsp;Std&nbsp;1003.1-2001). If any <b>-xdev</b> primary is specified, it shall apply to the entire
expression even if the <b>-xdev</b> primary would not normally be evaluated.</dd>
<dt><b>-prune</b></dt>
<dd>The primary shall always evaluate as true; it shall cause <i>find</i> not to descend the current pathname if it is a directory.
If the <b>-depth</b> primary is specified, the <b>-prune</b> primary shall have no effect.</dd>
<dt><b>-perm&nbsp;[-]</b><i>mode</i></dt>
<dd><br>
The <i>mode</i> argument is used to represent file mode bits. It shall be identical in format to the <i>symbolic_mode</i> operand
described in <a href="chmod.html"><i>chmod</i>()</a> , and shall be interpreted as follows. To start, a template shall be assumed
with all file mode bits cleared. An <i>op</i> symbol of <tt>'+'</tt> shall set the appropriate mode bits in the template;
<tt>'-'</tt> shall clear the appropriate bits; <tt>'='</tt> shall set the appropriate mode bits, without regard to the contents of
process' file mode creation mask. The <i>op</i> symbol of <tt>'-'</tt> cannot be the first character of <i>mode</i>; this avoids
ambiguity with the optional leading hyphen. Since the initial mode is all bits off, there are not any symbolic modes that need to
use <tt>'-'</tt> as the first character.
<p>If the hyphen is omitted, the primary shall evaluate as true when the file permission bits exactly match the value of the
resulting template.</p>
<p>Otherwise, if <i>mode</i> is prefixed by a hyphen, the primary shall evaluate as true if at least all the bits in the resulting
template are set in the file permission bits.</p>
</dd>
<dt><b>-perm&nbsp;[-]</b><i>onum</i></dt>
<dd><br>
If the hyphen is omitted, the primary shall evaluate as true when the file permission bits exactly match the value of the octal
number <i>onum</i> and only the bits corresponding to the octal mask 07777 shall be compared. (See the description of the octal
<i>mode</i> in <a href="chmod.html"><i>chmod</i>()</a> .) Otherwise, if <i>onum</i> is prefixed by a hyphen, the primary shall
evaluate as true if at least all of the bits specified in <i>onum</i> that are also set in the octal mask 07777 are set.</dd>
<dt><b>-type&nbsp;</b> <i>c</i></dt>
<dd>The primary shall evaluate as true if the type of the file is <i>c</i>, where <i>c</i> is <tt>'b'</tt> , <tt>'c'</tt> ,
<tt>'d'</tt> , <tt>'l'</tt> , <tt>'p'</tt> , <tt>'f'</tt> , or <tt>'s'</tt> for block special file, character special file,
directory, symbolic link, FIFO, regular file, or socket, respectively.</dd>
<dt><b>-links&nbsp;</b> <i>n</i></dt>
<dd>The primary shall evaluate as true if the file has <i>n</i> links.</dd>
<dt><b>-user&nbsp;</b> <i>uname</i></dt>
<dd>The primary shall evaluate as true if the file belongs to the user <i>uname.</i> If <i>uname</i> is a decimal integer and the
<a href="../functions/getpwnam.html"><i>getpwnam</i>()</a> (or equivalent) function does not return a valid user name, <i>uname</i>
shall be interpreted as a user ID.</dd>
<dt><b>-group&nbsp;</b> <i>gname</i></dt>
<dd><br>
The primary shall evaluate as true if the file belongs to the group <i>gname</i>. If <i>gname</i> is a decimal integer and the <a
href="../functions/getgrnam.html"><i>getgrnam</i>()</a> (or equivalent) function does not return a valid group name, <i>gname</i>
shall be interpreted as a group ID.</dd>
<dt><b>-size&nbsp;</b> <i>n</i><b>[c]</b></dt>
<dd>The primary shall evaluate as true if the file size in bytes, divided by 512 and rounded up to the next integer, is <i>n</i>.
If <i>n</i> is followed by the character <tt>'c'</tt> , the size shall be in bytes.</dd>
<dt><b>-atime&nbsp;</b> <i>n</i></dt>
<dd>The primary shall evaluate as true if the file access time subtracted from the initialization time, divided by 86400 (with any
remainder discarded), is <i>n</i>.</dd>
<dt><b>-ctime&nbsp;</b> <i>n</i></dt>
<dd>The primary shall evaluate as true if the time of last change of file status information subtracted from the initialization
time, divided by 86400 (with any remainder discarded), is <i>n</i>.</dd>
<dt><b>-mtime&nbsp;</b> <i>n</i></dt>
<dd>The primary shall evaluate as true if the file modification time subtracted from the initialization time, divided by 86400
(with any remainder discarded), is <i>n</i>.</dd>
<dt><b>-exec&nbsp;</b> <i>utility_name&nbsp;</i> <b>[</b><i>argument</i>&nbsp;...<b>]&nbsp;;</b></dt>
<dt><b>-exec&nbsp;</b> <i>utility_name&nbsp;</i> <b>[</b><i>argument</i>&nbsp;...<b>]&nbsp;&nbsp;</b> {}&nbsp;+</dt>
<dd><br>
The end of the primary expression shall be punctuated by a semicolon or by a plus sign. Only a plus sign that follows an argument
containing the two characters <tt>"{}"</tt> shall punctuate the end of the primary expression. Other uses of the plus sign shall
not be treated as special.
<p>If the primary expression is punctuated by a semicolon, the utility <i>utility_name</i> shall be invoked once for each pathname
and the primary shall evaluate as true if the utility returns a zero value as exit status. A <i>utility_name</i> or <i>argument</i>
containing only the two characters <tt>"{}"</tt> shall be replaced by the current pathname.</p>
<p>If the primary expression is punctuated by a plus sign, the primary shall always evaluate as true, and the pathnames for which
the primary is evaluated shall be aggregated into sets. The utility <i>utility_name</i> shall be invoked once for each set of
aggregated pathnames. Each invocation shall begin after the last pathname in the set is aggregated, and shall be completed before
the <i>find</i> utility exits and before the first pathname in the next set (if any) is aggregated for this primary, but it is
otherwise unspecified whether the invocation occurs before, during, or after the evaluations of other primaries. If any invocation
returns a non-zero value as exit status, the <i>find</i> utility shall return a non-zero exit status. An argument containing only
the two characters <tt>"{}"</tt> shall be replaced by the set of aggregated pathnames, with each pathname passed as a separate
argument to the invoked utility in the same order that it was aggregated. The size of any set of two or more pathnames shall be
limited such that execution of the utility does not cause the system's {ARG_MAX} limit to be exceeded. If more than one argument
containing only the two characters <tt>"{}"</tt> is present, the behavior is unspecified.</p>
<p>If a <i>utility_name</i> or <i>argument</i> string contains the two characters <tt>"{}"</tt> , but not just the two characters
<tt>"{}"</tt> , it is implementation-defined whether <i>find</i> replaces those two characters or uses the string without change.
The current directory for the invocation of <i>utility_name</i> shall be the same as the current directory when the <i>find</i>
utility was started. If the <i>utility_name</i> names any of the special built-in utilities (see <a href=
"xcu_chap02.html#tag_02_14"><i>Special Built-In Utilities</i></a> ), the results are undefined.</p>
</dd>
<dt><b>-ok&nbsp;</b> <i>utility_name&nbsp;</i> <b>[</b><i>argument</i>&nbsp;...<b>]&nbsp;;</b></dt>
<dd><br>
The <b>-ok</b> primary shall be equivalent to <b>-exec</b>, except that the use of a plus sign to punctuate the end of the primary
expression need not be supported, and <i>find</i> shall request affirmation of the invocation of <i>utility_name</i> using the
current file as an argument by writing to standard error as described in the STDERR section. If the response on standard input is
affirmative, the utility shall be invoked. Otherwise, the command shall not be invoked and the value of the <b>-ok</b> operand
shall be false.</dd>
<dt><b>-print</b></dt>
<dd>The primary shall always evaluate as true; it shall cause the current pathname to be written to standard output.</dd>
<dt><b>-newer&nbsp;</b> <i>file</i></dt>
<dd>The primary shall evaluate as true if the modification time of the current file is more recent than the modification time of
the file named by the pathname <i>file</i>.</dd>
<dt><b>-depth</b></dt>
<dd>The primary shall always evaluate as true; it shall cause descent of the directory hierarchy to be done so that all entries in
a directory are acted on before the directory itself. If a <b>-depth</b> primary is not specified, all entries in a directory shall
be acted on after the directory itself. If any <b>-depth</b> primary is specified, it shall apply to the entire expression even if
the <b>-depth</b> primary would not normally be evaluated.</dd>
</dl>
<p>The primaries can be combined using the following operators (in order of decreasing precedence):</p>
<dl compact>
<dt>(&nbsp;<i>expression</i>&nbsp;)</dt>
<dd>True if <i>expression</i> is true.</dd>
<dt><b>!&nbsp;</b> <i>expression</i></dt>
<dd>Negation of a primary; the unary NOT operator.</dd>
<dt><i>expression&nbsp;</i> <b>[-a]&nbsp;</b> <i>expression</i></dt>
<dd><br>
Conjunction of primaries; the AND operator is implied by the juxtaposition of two primaries or made explicit by the optional
<b>-a</b> operator. The second expression shall not be evaluated if the first expression is false.</dd>
<dt><i>expression&nbsp;</i> <b>-o&nbsp;</b> <i>expression</i></dt>
<dd><br>
Alternation of primaries; the OR operator. The second expression shall not be evaluated if the first expression is true.</dd>
</dl>
<p>If no <i>expression</i> is present, <b>-print</b> shall be used as the expression. Otherwise, if the given expression does not
contain any of the primaries <b>-exec</b>, <b>-ok</b>, or <b>-print</b>, the given expression shall be effectively replaced by:</p>
<pre>
<tt>(</tt> <i>given_expression</i> <tt>) -print
</tt>
</pre>
<p>The <b>-user</b>, <b>-group</b>, and <b>-newer</b> primaries each shall evaluate their respective arguments only once.</p>
</blockquote>
<h4><a name="tag_04_55_06"></a>STDIN</h4>
<blockquote>
<p>If the <b>-ok</b> primary is used, the response shall be read from the standard input. An entire line shall be read as the
response. Otherwise, the standard input shall not be used.</p>
</blockquote>
<h4><a name="tag_04_55_07"></a>INPUT FILES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_55_08"></a>ENVIRONMENT VARIABLES</h4>
<blockquote>
<p>The following environment variables shall affect the execution of <i>find</i>:</p>
<dl compact>
<dt><i>LANG</i></dt>
<dd>Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of
IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/xbd_chap08.html#tag_08_02">Section 8.2, Internationalization Variables</a> for
the precedence of internationalization variables used to determine the values of locale categories.)</dd>
<dt><i>LC_ALL</i></dt>
<dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd>
<dt><i>LC_COLLATE</i></dt>
<dd><br>
Determine the locale for the behavior of ranges, equivalence classes, and multi-character collating elements used in the pattern
matching notation for the <b>-n</b> option and in the extended regular expression defined for the <b>yesexpr</b> locale keyword in
the <i>LC_MESSAGES</i> category.</dd>
<dt><i>LC_CTYPE</i></dt>
<dd>This variable determines the locale for the interpretation of sequences of bytes of text data as characters (for example,
single-byte as opposed to multi-byte characters in arguments), the behavior of character classes within the pattern matching
notation used for the <b>-n</b> option, and the behavior of character classes within regular expressions used in the extended
regular expression defined for the <b>yesexpr</b> locale keyword in the <i>LC_MESSAGES</i> category.</dd>
<dt><i>LC_MESSAGES</i></dt>
<dd>Determine the locale for the processing of affirmative responses that should be used to affect the format and contents of
diagnostic messages written to standard error.</dd>
<dt><i>NLSPATH</i></dt>
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
Determine the location of message catalogs for the processing of <i>LC_MESSAGES .</i> <img src="../images/opt-end.gif" alt=
"[Option End]" border="0"></dd>
<dt><i>PATH</i></dt>
<dd>Determine the location of the <i>utility_name</i> for the <b>-exec</b> and <b>-ok</b> primaries, as described in the Base
Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/xbd_chap08.html">Chapter 8, Environment
Variables</a>.</dd>
</dl>
</blockquote>
<h4><a name="tag_04_55_09"></a>ASYNCHRONOUS EVENTS</h4>
<blockquote>
<p>Default.</p>
</blockquote>
<h4><a name="tag_04_55_10"></a>STDOUT</h4>
<blockquote>
<p>The <b>-print</b> primary shall cause the current pathnames to be written to standard output. The format shall be:</p>
<pre>
<tt>"%s\n", &lt;</tt><i>path</i><tt>&gt;
</tt>
</pre>
</blockquote>
<h4><a name="tag_04_55_11"></a>STDERR</h4>
<blockquote>
<p>The <b>-ok</b> primary shall write a prompt to standard error containing at least the <i>utility_name</i> to be invoked and the
current pathname. In the POSIX locale, the last non- &lt;blank&gt; in the prompt shall be <tt>'?'</tt> . The exact format used is
unspecified.</p>
<p>Otherwise, the standard error shall be used only for diagnostic messages.</p>
</blockquote>
<h4><a name="tag_04_55_12"></a>OUTPUT FILES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_55_13"></a>EXTENDED DESCRIPTION</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_55_14"></a>EXIT STATUS</h4>
<blockquote>
<p>The following exit values shall be returned:</p>
<dl compact>
<dt>&nbsp;0</dt>
<dd>All <i>path</i> operands were traversed successfully.</dd>
<dt>&gt;0</dt>
<dd>An error occurred.</dd>
</dl>
</blockquote>
<h4><a name="tag_04_55_15"></a>CONSEQUENCES OF ERRORS</h4>
<blockquote>
<p>Default.</p>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_04_55_16"></a>APPLICATION USAGE</h4>
<blockquote>
<p>When used in operands, pattern matching notation, semicolons, opening parentheses, and closing parentheses are special to the
shell and must be quoted (see <a href="xcu_chap02.html#tag_02_02"><i>Quoting</i></a> ).</p>
<p>The bit that is traditionally used for sticky (historically 01000) is specified in the <b>-perm</b> primary using the octal
number argument form. Since this bit is not defined by this volume of IEEE&nbsp;Std&nbsp;1003.1-2001, applications must not assume
that it actually refers to the traditional sticky bit.</p>
</blockquote>
<h4><a name="tag_04_55_17"></a>EXAMPLES</h4>
<blockquote>
<ol>
<li>
<p>The following commands are equivalent:</p>
<pre>
<tt>find .
find . -print
</tt>
</pre>
<p>They both write out the entire directory hierarchy from the current directory.</p>
</li>
<li>
<p>The following command:</p>
<pre>
<tt>find / \( -name tmp -o -name '*.xx' \) -atime +7 -exec rm {} \;
</tt>
</pre>
<p>removes all files named <b>tmp</b> or ending in <b>.xx</b> that have not been accessed for seven or more 24-hour periods.</p>
</li>
<li>
<p>The following command:</p>
<pre>
<tt>find . -perm -o+w,+s
</tt>
</pre>
<p>prints ( <b>-print</b> is assumed) the names of all files in or below the current directory, with all of the file permission
bits S_ISUID, S_ISGID, and S_IWOTH set.</p>
</li>
<li>
<p>The following command:</p>
<pre>
<tt>find . -name SCCS -prune -o -print
</tt>
</pre>
<p>recursively prints pathnames of all files in the current directory and below, but skips directories named SCCS and files in
them.</p>
</li>
<li>
<p>The following command:</p>
<pre>
<tt>find . -print -name SCCS -prune
</tt>
</pre>
<p>behaves as in the previous example, but prints the names of the SCCS directories.</p>
</li>
<li>
<p>The following command is roughly equivalent to the <b>-nt</b> extension to <a href="../utilities/test.html"><i>test</i></a>:</p>
<pre>
<tt>if [ -n "$(find file1 -prune -newer file2)" ]; then
printf %s\\n "file1 is newer than file2"
fi
</tt>
</pre>
</li>
<li>
<p>The descriptions of <b>-atime</b>, <b>-ctime</b>, and <b>-mtime</b> use the terminology <i>n</i> &quot;86400 second periods
(days)&quot;. For example, a file accessed at 23:59 is selected by:</p>
<pre>
<tt>find . -atime -1 -print
</tt>
</pre>
<p>at 00:01 the next day (less than 24 hours later, not more than one day ago); the midnight boundary between days has no effect on
the 24-hour calculation.</p>
</li>
</ol>
</blockquote>
<h4><a name="tag_04_55_18"></a>RATIONALE</h4>
<blockquote>
<p>The <b>-a</b> operator was retained as an optional operator for compatibility with historical shell scripts, even though it is
redundant with expression concatenation.</p>
<p>The descriptions of the <tt>'-'</tt> modifier on the <i>mode</i> and <i>onum</i> arguments to the <b>-perm</b> primary agree
with historical practice on BSD and System V implementations. System V and BSD documentation both describe it in terms of checking
additional bits; in fact, it uses the same bits, but checks for having at least all of the matching bits set instead of having
exactly the matching bits set.</p>
<p>The exact format of the interactive prompts is unspecified. Only the general nature of the contents of prompts are specified
because:</p>
<ul>
<li>
<p>Implementations may desire more descriptive prompts than those used on historical implementations.</p>
</li>
<li>
<p>Since the historical prompt strings do not terminate with &lt;newline&gt;s, there is no portable way for another program to
interact with the prompts of this utility via pipes.</p>
</li>
</ul>
<p>Therefore, an application using this prompting option relies on the system to provide the most suitable dialog directly with the
user, based on the general guidelines specified.</p>
<p>The <b>-name</b> <i>file</i> operand was changed to use the shell pattern matching notation so that <i>find</i> is consistent
with other utilities using pattern matching.</p>
<p>The <b>-size</b> operand refers to the size of a file, rather than the number of blocks it may occupy in the file system. The
intent is that the <i>st_size</i> field defined in the System Interfaces volume of IEEE&nbsp;Std&nbsp;1003.1-2001 should be used,
not the <i>st_blocks</i> found in historical implementations. There are at least two reasons for this:</p>
<ol>
<li>
<p>In both System V and BSD, <i>find</i> only uses <i>st_size</i> in size calculations for the operands specified by this volume of
IEEE&nbsp;Std&nbsp;1003.1-2001. (BSD uses <i>st_blocks</i> only when processing the <b>-ls</b> primary.)</p>
</li>
<li>
<p>Users usually think of file size in terms of bytes, which is also the unit used by the <a href=
"../utilities/ls.html"><i>ls</i></a> utility for the output from the <b>-l</b> option. (In both System V and BSD, <a href=
"../utilities/ls.html"><i>ls</i></a> uses <i>st_size</i> for the <b>-l</b> option size field and uses <i>st_blocks</i> for the <a
href="../utilities/ls.html"><i>ls</i></a> <b>-s</b> calculations. This volume of IEEE&nbsp;Std&nbsp;1003.1-2001 does not specify <a
href="../utilities/ls.html"><i>ls</i></a> <b>-s</b>.)</p>
</li>
</ol>
<p>The descriptions of <b>-atime</b>, <b>-ctime</b>, and <b>-mtime</b> were changed from the SVID description of <i>n</i> &quot;days''
to &quot;24-hour periods&quot;. The description is also different in terms of the exact timeframe for the <i>n</i> case (<i>versus</i> the
<i>+n</i> or <i>-n</i>), but it matches all known historical implementations. It refers to one 86400 second period in the past, not
any time from the beginning of that period to the current time. For example, <b>-atime</b> 3 is true if the file was accessed any
time in the period from 72 hours to 48 hours ago.</p>
<p>Historical implementations do not modify <tt>"{}"</tt> when it appears as a substring of an <b>-exec</b> or <b>-ok</b>
<i>utility_name</i> or argument string. There have been numerous user requests for this extension, so this volume of
IEEE&nbsp;Std&nbsp;1003.1-2001 allows the desired behavior. At least one recent implementation does support this feature, but
encountered several problems in managing memory allocation and dealing with multiple occurrences of <tt>"{}"</tt> in a string while
it was being developed, so it is not yet required behavior.</p>
<p>Assuming the presence of <b>-print</b> was added to correct a historical pitfall that plagues novice users, it is entirely
upwards-compatible from the historical System V <i>find</i> utility. In its simplest form ( <i>find</i> <i>directory</i>), it could
be confused with the historical BSD fast <i>find</i>. The BSD developers agreed that adding <b>-print</b> as a default expression
was the correct decision and have added the fast <i>find</i> functionality within a new utility called <i>locate</i>.</p>
<p>Historically, the <b>-L</b> option was implemented using the primary <b>-follow</b>. The <b>-H</b> and <b>-L</b> options were
added for two reasons. First, they offer a finer granularity of control and consistency with other programs that walk file
hierarchies. Second, the <b>-follow</b> primary always evaluated to true. As they were historically really global variables that
took effect before the traversal began, some valid expressions had unexpected results. An example is the expression <b>-print</b>
<b>-o</b> <b>-follow</b>. Because <b>-print</b> always evaluates to true, the standard order of evaluation implies that
<b>-follow</b> would never be evaluated. This was never the case. Historical practice for the <b>-follow</b> primary, however, is
not consistent. Some implementations always follow symbolic links on the command line whether <b>-follow</b> is specified or not.
Others follow symbolic links on the command line only if <b>-follow</b> is specified. Both behaviors are provided by the <b>-H</b>
and <b>-L</b> options, but scripts using the current <b>-follow</b> primary would be broken if the <b>-follow</b> option is
specified to work either way.</p>
<p>Since the <b>-L</b> option resolves all symbolic links and the <b>-type</b> <i>l</i> primary is true for symbolic links that
still exist after symbolic links have been resolved, the command:</p>
<pre>
<tt>find -L . -type l
</tt>
</pre>
<p>prints a list of symbolic links reachable from the current directory that do not resolve to accessible files.</p>
<p>A feature of SVR4's <i>find</i> utility was the <b>-exec</b> primary's <b>+</b> terminator. This allowed filenames containing
special characters (especially &lt;newline&gt;s) to be grouped together without the problems that occur if such filenames are piped
to <a href="../utilities/xargs.html"><i>xargs</i></a>. Other implementations have added other ways to get around this problem,
notably a <b>-print0</b> primary that wrote filenames with a null byte terminator. This was considered here, but not adopted. Using
a null terminator meant that any utility that was going to process <i>find</i>'s <b>-print0</b> output had to add a new option to
parse the null terminators it would now be reading.</p>
<p>The <tt>"-exec ... {} +"</tt> syntax adopted was a result of IEEE PASC Interpretation 1003.2 #210. It should be noted that this
is an incompatible change to the ISO/IEC&nbsp;9899:1999 standard. For example, the following command prints all files with a
<tt>'-'</tt> after their name if they are regular files, and a <tt>'+'</tt> otherwise:</p>
<pre>
<tt>find / -type f -exec echo {} - ';' -o -exec echo {} + ';'
</tt>
</pre>
<p>The change invalidates usage like this. Even though the previous standard stated that this usage would work, in practice many
did not support it and the standard developers felt it better to now state that this was not allowable.</p>
</blockquote>
<h4><a name="tag_04_55_19"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_55_20"></a>SEE ALSO</h4>
<blockquote>
<p><a href="xcu_chap02.html#tag_02_02"><i>Quoting</i></a> , <a href="xcu_chap02.html#tag_02_13"><i>Pattern Matching
Notation</i></a> , <a href="xcu_chap02.html#tag_02_14"><i>Special Built-In Utilities</i></a> , <a href=
"chmod.html"><i>chmod</i>()</a> , <a href="pax.html"><i>pax</i></a> , <a href="sh.html"><i>sh</i></a> , <a href=
"test.html"><i>test</i></a> , the System Interfaces volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../functions/getgrgid.html"><i>getgrgid</i>()</a>, <a href="../functions/getpwuid.html"><i>getpwuid</i>()</a>, <a href=
"../functions/stat.html"><i>stat</i>()</a></p>
</blockquote>
<h4><a name="tag_04_55_21"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 2.</p>
</blockquote>
<h4><a name="tag_04_55_22"></a>Issue 5</h4>
<blockquote>
<p>The FUTURE DIRECTIONS section is added.</p>
</blockquote>
<h4><a name="tag_04_55_23"></a>Issue 6</h4>
<blockquote>
<p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p>
<ul>
<li>
<p>The <b>-perm&nbsp;[-]</b><i>onum</i> primary is supported.</p>
</li>
</ul>
<p>The <i>find</i> utility is aligned with the IEEE&nbsp;P1003.2b draft standard, to include processing of symbolic links and
changes to the description of the <b>atime</b>, <b>ctime</b>, and <b>mtime</b> operands.</p>
<p>IEEE PASC Interpretation 1003.2 #210 is applied, extending the <b>-exec</b> operand.</p>
</blockquote>
<div class="box"><em>End of informative text.</em></div>
<hr>
<hr size="2" noshade>
<center><font size="2"><!--footer start-->
UNIX &reg; is a registered Trademark of The Open Group.<br>
POSIX &reg; is a registered Trademark of The IEEE.<br>
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
]</font></center>
<!--footer end-->
<hr size="2" noshade>
</body>
</html>