Re: A linux commad
- From: jt@xxxxxxxxxxx (Jens Thoms Toerring)
- Date: 6 Jun 2010 13:43:02 GMT
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
.
- Follow-Ups:
- Re: A linux commad
- From: qiujiahao
- Re: A linux commad
- References:
- A linux commad
- From: qiujiahao
- A linux commad
- Prev by Date: A linux commad
- Next by Date: Re: A linux commad
- Previous by thread: A linux commad
- Next by thread: Re: A linux commad
- Index(es):
Relevant Pages
|