Re: A linux commad



qiujiahao@xxxxxxxxx wrote:
[root@cts5 linux]# find /usr/include/linux -name "*.h" -exec grep "*mode_t"
{} \;

##This command can find soma result;##

[root@cts5 linux]# find /usr/include/linux -name "*.h" -exec grep "mode_t"
{} \;

##This command can't find no one;##

why ?
Can't use '*' in grep command under the find ?

grep uses regular expressions which are different from e.g. shell
expansion where the '*' stands for one or more arbitrary characters.
In grep the '*' is a quantifier saying "look for all places where
the item preceeding the '*' appears zero or more times". Actually,
you hit on a special case here: when the search string starts with
a '*' the '*' doesn't make sense as a quantifier and is thus con-
sidered to mean that you look for an actual '*' in the text. Thus

grep '*mode_t'

will look for all instances of a '*' followed directly by 'mode"t'
in the input and is thus the same as

grep '\*mode_t'

So what seems to be missing is something before the '*' that is
to appear zero or more times. If you look for nothing special
before the '*' put a '.' in front of it - the '.' stands for
"an arbitrary character". So the correct form is be

grep '.*mode_t'

Of course, in this context it makes no difference to "grep 'mode_t'".
Should you be looking for all instances where 'mode_t' is preceeded
by at least one (arbitrary) character you would need

grep '.mode_t'
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@xxxxxxxxxxx
\__________________________ http://toerring.de
.



Relevant Pages

  • Re: A linux commad
    ... In grep the '*' is a quantifier saying "look for all places where ... the item preceeding the '*' appears zero or more times". ... Can't use '*' in grep command under the find? ...
    (comp.os.linux.development.apps)
  • Re: Ignoring trap command for a grep function
    ... when the grep command does not match any lines in the input ... returns zero as its exit code. ... >> involving the use of trap in and around the trap statement. ... echo not found ...
    (comp.unix.solaris)
  • Re: Ignoring trap command for a grep function
    ... when the grep command does not match any lines in the input ... returns zero as its exit code. ... >> involving the use of trap in and around the trap statement. ... echo not found ...
    (comp.unix.programmer)
  • Re: Ignoring trap command for a grep function
    ... when the grep command does not match any lines in the input ... returns zero as its exit code. ... >> involving the use of trap in and around the trap statement. ... echo not found ...
    (comp.unix.shell)
  • Re: Ignoring trap command for a grep function
    ... when the grep command does not match any lines in the input ... returns zero as its exit code. ... >> involving the use of trap in and around the trap statement. ... echo not found ...
    (comp.unix.sco.misc)