On Thu, Feb 25, 2010 at 10:42 AM, James Youngman <[email protected]> wrote:
> On Thu, Feb 25, 2010 at 5:29 AM, Reza Roboubi <[email protected]> wrote:
>> find . -wholename './src/emacs/' -prune -o -print   (extra slash)
>>
>> and that wasn't working.  Why is that?
>
> Because path names examined by find never include a trailing slash.
>
> Similarly "find -name a/b" will never find anything, since -name only
> works with files' base names (i.e. with the directory part removed)
> and so they never include a slash.
>
> The manpage should probably point out both facts.

The manpage already points this out for -path (and hence -wholename):

              Find  compares  the  -path  argument with the concatenation of a
              directory name and the base name of  the  file  it’s  examining.
              Since the concatenation will never end with a slash, -path argu‐
              ments ending in a slash will match  nothing  (except  perhaps  a
              start point specified on the command line).

I just pushed the attached patch to deal with -name better.

James.
From d4f2e4453e06920f1d14804c1cfa9b3f81d8dd39 Mon Sep 17 00:00:00 2001
From: James Youngman <[email protected]>
Date: Thu, 25 Feb 2010 11:06:53 +0000
Subject: [PATCH] Explain the problems with "-name a/b" and "-path foo/".
To: [email protected]

* find/find.1 (-iname): We already refer to -name, so duplicate
less text.
(-name): Explain that -name a/b will never match anything.
* doc/find.texi (Base Name Patterns): Explain that -name a/b will
never match anything.
(Full Name Patterns): Fix typo.

Signed-off-by: James Youngman <[email protected]>
---
 ChangeLog     |   10 ++++++++++
 doc/find.texi |    9 +++++++--
 find/find.1   |   16 +++++++++-------
 3 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 50df6c1..03fffbc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2010-02-25  James Youngman  <[email protected]>
+
+	Explain the problems with "-name a/b" and "-path foo/".
+	* find/find.1 (-iname): We already refer to -name, so duplicate
+	less text.
+	(-name): Explain that -name a/b will never match anything.
+	* doc/find.texi (Base Name Patterns): Explain that -name a/b will
+	never match anything.
+	(Full Name Patterns): Fix typo.
+
 2010-02-22  James Youngman  <[email protected]>
 
 	* xargs/xargs.1: Simplify the wording in the description of "xargs
diff --git a/doc/find.texi b/doc/find.texi
index 7820c43..c2c2c03 100644
--- a/doc/find.texi
+++ b/doc/find.texi
@@ -404,6 +404,11 @@ example the command @samp{find /tmp -name \*bar} will match the file
 considered to be special (that is, @code{find . -name 'f...@{1,2...@}'}
 matches a file named @file{...@{1,2...@}}, not the files @file{foo1} and
 @file{foo2}.
+
+Because the leading directories are removed, the file names considered
+for a match with @samp{-name} will never include a slash, so
+...@samp{-name a/b} will never match anything (you probably need to use
+...@samp{-path} instead).
 @end deffn
 
 
@@ -428,8 +433,8 @@ arguments ending in @samp{/} will match nothing (except perhaps a
 start point specified on the command line).
 
 The name @samp{-wholename} is GNU-specific, but @samp{-path} is more
-portable; it is supported by HP-UX @code{find} and is of the POSIX
-2008 standard.
+portable; it is supported by HP-UX @code{find} and is part of the
+POSIX 2008 standard.
 
 @end deffn
 
diff --git a/find/find.1 b/find/find.1
index b27311a..e17b21e 100644
--- a/find/find.1
+++ b/find/find.1
@@ -584,12 +584,8 @@ Like
 .BR \-name ,
 but the match is case insensitive.  For example, the
 patterns `fo*' and `F??' match the file names `Foo', `FOO', `foo',
-`fOo', etc.   In these patterns, unlike filename expansion by the
-shell, an initial `.' can be matched by `*'.  That is,
-.B find \-name *bar
-will match the file `.foobar'.   Please note that you should quote
-patterns as a matter of course, otherwise the shell will expand any
-wildcard characters in them.
+`fOo', etc.   The pattern `*foo*` will also match a file
+called '.foobar'.
 
 .IP "\-inum \fIn\fR"
 File has inode number \fIn\fR.  It is normally easier to use the
@@ -635,7 +631,13 @@ modification times.
 
 .IP "\-name \fIpattern\fR"
 Base of file name (the path with the leading directories removed)
-matches shell pattern \fIpattern\fR.  The metacharacters (`*', `?',
+matches shell pattern \fIpattern\fR.  Because the leading directories
+are removed, the file names considered for a match with
+.B \-name
+will never include a slash, so `-name a/b' will never match anything
+(you probably need to use
+.B \-path
+instead).  The metacharacters (`*', `?',
 and `[]') match a `.' at the start of the base name (this is a change
 in findutils-4.2.2; see section STANDARDS CONFORMANCE below).  To ignore a
 directory and the files under it, use
-- 
1.5.6.5

Reply via email to