Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to grep all the subdirectories?

389 views
Skip to first unread message

Leung Yuk Leong Daniel

unread,
Nov 2, 2000, 3:24:58 AM11/2/00
to
Hello,
Anyone one know the command that can use to grep all the files inside
the subdirectories of the current directory?
Thx.
Daniel

Mihai Cartoaje

unread,
Nov 2, 2000, 4:01:55 AM11/2/00
to

grep "my string" `find .`

Mihai

Roland Titze

unread,
Nov 2, 2000, 4:22:33 AM11/2/00
to
Leung Yuk Leong Daniel wrote:
>
find . -type f | xargs grep <pattern>
--

Regards/MfG
Roland Titze

Christian Zander

unread,
Nov 2, 2000, 4:45:14 AM11/2/00
to
Try grep -r -e '<pattern>' *

Leung Yuk Leong Daniel schrieb:

hans mayer

unread,
Nov 2, 2000, 9:36:34 AM11/2/00
to
In article <8tr8cq$pq...@hkunae.hku.hk>,

Leung Yuk Leong Daniel <yldl...@faith.csis.hku.hk> wrote:
> Anyone one know the command that can use to grep all the files inside
>the subdirectories of the current directory?

find . -name '*string*' -print


--
best regards from vienna |
hans | mayer (at) relay.bfl.at_SPAM

Hector Davie

unread,
Nov 2, 2000, 9:52:41 AM11/2/00
to
In article <3A0137AA...@nt-nv.fh-koeln.de>,

What is this -r switch?

grep: illegal option -- r

How about:
grep '<pattern>' `find .`
or better:
find . -exec grep 'pattern' {} \;

--
p_n__n__---- _____ Hector Davie
d ___--__|HH|| `---. Ascom Hasler AG, Berne, Switzerland
_T-------'__-|_________| hec...@tell.ascom.ch
'o=o ()()()-' o=o`-'o=o Phone: (+41) 031 999 28 86

Rosana

unread,
Nov 2, 2000, 12:11:48 PM11/2/00
to
Hector Davie wrote:

This works for me too:

ls -R */pattern

One drawback is it will recursively list all subdirectories.

Peter Sundstrom

unread,
Nov 2, 2000, 3:45:53 PM11/2/00
to

Christian Zander <christia...@nt-nv.fh-koeln.de> wrote in message
news:3A0137AA...@nt-nv.fh-koeln.de...

>
> Leung Yuk Leong Daniel schrieb:
>
> > Hello,
> > Anyone one know the command that can use to grep all the files
inside
> > the subdirectories of the current directory?
> > Thx.
> > Daniel
>
> Try grep -r -e '<pattern>' *

But only if you have GNU grep installed, which is not the Solaris default.

j...@frii.com

unread,
Nov 4, 2000, 3:00:00 AM11/4/00
to
% find . -type f -exec grep pattern {} /dev/null \;

Leung Yuk Leong Daniel <yldl...@faith.csis.hku.hk> wrote:

--
John W. Kennedy

Gopala

unread,
Nov 4, 2000, 3:00:00 AM11/4/00
to
I prefer find . -type f -exec grep -i "pattern" {} /dev/null \; to the
xargs one, coz.. in the later, SHELL limitations.. come into picture
and it may fail.. when the list gets too longer.

Gopi.


j...@frii.com wrote:
> % find . -type f -exec grep pattern {} /dev/null \;
>


Sent via Deja.com http://www.deja.com/
Before you buy.

Logan Shaw

unread,
Nov 4, 2000, 3:00:00 AM11/4/00
to
In article <8u1hja$kp8$1...@nnrp1.deja.com>, Gopala <gmol...@my-deja.com> wrote:
>I prefer find . -type f -exec grep -i "pattern" {} /dev/null \; to the
>xargs one, coz.. in the later, SHELL limitations.. come into picture
>and it may fail.. when the list gets too longer.

It shouldn't fail when the list gets too long. That's the whole
purpose of "xargs" -- to fit just as many arguments onto the command
line as will be allowed.

The "find"/"xargs" combo will fail, though, when the filename contains
newlines or other special characters, since there is a stream of
newline-separated filenames going from one to the other, and it's
possible to disturb the structure by adding your own newlines.

- Logan

Uwe Wolfram

unread,
Nov 6, 2000, 3:00:00 AM11/6/00
to
Hi Logan!

LS> The "find"/"xargs" combo will fail, though, when the filename
contains
LS> newlines or other special characters, since there is a stream of
LS> newline-separated filenames going from one to the other, and it's
LS> possible to disturb the structure by adding your own newlines.

Not a specific reply to your's, but

may I point everyone to this nice little tool called tgrep from Sun.
It does a multithreaded recursive grep (very fast on multi cpu
machines).
I don't know where I got it from (source code), but a search on the Web
should give the right answer.

Uwe

Logan Shaw

unread,
Nov 6, 2000, 3:00:00 AM11/6/00
to
In article <MSGID_2=3A2453=2F30.205=40fidonet...@fidonet.org>,

Uwe Wolfram <Uwe_W...@zaphod.fido.de> wrote:
>may I point everyone to this nice little tool called tgrep from Sun.

Apparently, according to http://www.bconnex.net/~ronw/tgrep/ , this
utility was written by someone else and used by Sun as an example of
threads-based programming. The reason I mention this is that the
version Sun used is said to be out of date.

- Logan

William F. Wyatt

unread,
Nov 9, 2000, 3:00:00 AM11/9/00
to Logan Shaw
>
> The "find"/"xargs" combo will fail, though, when the filename contains
> newlines or other special characters, since there is a stream of
> newline-separated filenames going from one to the other, and it's
> possible to disturb the structure by adding your own newlines.
>

Yes, but if you use the GNU version of these, there's a -print0
option on the find and a -0 option to xargs which prints and expects
a null-terminated string, respectively. We use this version and
it has been quite successful.

--
Bill Wyatt (REMOVEw...@cfa.harvard.edu) "remove this" for email
Smithsonian Astrophysical Observatory (Cambridge, MA, USA)

0 new messages