[Cialug] Using find

Jeffrey C. Ollie jeff at ocjtech.us
Sat Jun 9 15:22:42 CDT 2007


On Sat, 2007-06-09 at 12:47 -0500, Josh More wrote:
> Likely because your shell is extrapolating the asterisks, resulting in
> something like "find . -regex this/ -print"
> 
> Try:
> 
> find . -regex '*this*' -print
> 
>  (Note, I couldn't duplicate the problem, but then I don't know which
> shell your running, and your respective versions of both the shell and
> findutils.  This is just a common answer to such a problem.)

The shell only expands globs if the globs actually match something.  So
if there's nothing that matches the glob in the current directory it'll
pass the '*' characters unchanged.  If there is something that matches,
the '*' characters will get substituted.  Here's a quick tip - type "set
-x" in your shell and it will print the commands that it's executing
after substituting variables and expanding globs.  Here's an example of
what is going on:

$ set -x
+ set -x
$ find . -name *this* -print
+ find . -name '*this*' -print
./dev/git.git/templates/this--description
./swfdec/test/trace/DoInitAction-this.swf.trace
./swfdec/test/trace/DoInitAction-this.swf
$ mkdir this_one
+ mkdir this_one
$ find . -name *this* -print
+ find . -name this_one -print
./this_one
$ mkdir or_this_one
+ mkdir or_this_one
$ find . -name *this* -print
+ find . -name or_this_one this_one -print
find: paths must precede expression
Usage: find [-H] [-L] [-P] [path...] [expression]
$ set +x

To get globs working in find, I always escape them with a backslash:

find . -name \*this\* -print

Jeff

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://cialug.org/pipermail/cialug/attachments/20070609/376fd209/attachment.pgp


More information about the Cialug mailing list