[X-Unix] Wildcard * in Pathnames

Philip J Robar philip.robar at gmail.com
Wed May 11 22:38:18 PDT 2005


On May 11, 2005, at 8:08 PM, Jerry Krinock wrote:

> In the arguments of various commands, for example "find" and "rm",  
> I would
> often like to match any path containing a given word with a wildcard
> expression like:
>
>     *Fruit*
>
> And I expect this to match _any_ pathname containing "Fruit",  
> including:
>
>     ~/Fruit/Apple/Seeds
>     /Applications/Fruit/Lemon.app
>     /Volumes/MyHD/Fruit
>
> but it never works.  The problem seems to be that the path separator
> character "/" is beyond the scope of the wildcard "*".  I can get the
> desired result if I search a set of wildcard expressions, such as:
>
>     /*/Fruit/*
>     /*/*Fruit/*
>     /Fruit/*/*/*/
>     etc.
>     etc.
>     etc.

     find [pathname ...] -name '*Fruit*'

or

     find [pathname ...] -name '*Fruit*' -exec rm {} \;


The single quotes around the search term prevent the asterisk meta  
characters from being expanded by the shell before the command is  
executed. Other options (-xdev, -type) can be used to limit the  
search to local drives and the type of files that will match the  
pattern.

"{}"    is the current matching pathname which gets passed to the  
command to be run by exec.

"\;"    the backslash keeps the semicolon from being interpreted by  
the shell. The semicolon closes -exec and
         its arguments.

The internet is littered with 'find' tutorials.


Phil




More information about the X-Unix mailing list