Subject: Re: Can grep work recursively?
From: mlw <[email-masked]>
Date: Wed, 30 Dec 1998 20:50:51 +0000
Newsgroups: comp.os.linux.advocacy,comp.os.linux.misc

[email-masked] wrote:

> I was wondering if it was possible to make grep work recursively in folders.
> Is this possible?
> 
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own

This might be the long way:

find . -name *.cpp -exec grep expression {} \;

From: [email-masked] (Tim Smith)
Newsgroups: comp.os.linux.advocacy,comp.os.linux.misc
Subject: Re: Can grep work recursively?
Date: 30 Dec 1998 16:58:43 -0800
Organization: Institute of Lawsonomy

mlw  <[email-masked]> wrote:
>This might be the long way:
>
>find . -name *.cpp -exec grep expression {} \;

Using find is a good approach, but that particular command doesn't quite
solve the problem.

(1) The "*.cpp" needs to be quoted to prevent the shell from expanding
it, or you might miss some files.

(2) It invokes one grep per file.  When there are less than two file
arguments to grep, grep doesn't print the name of the file.  This will
make it hard to tell which files the matches come from.

(3) One grep per file is inefficient.

Try something like this:

	find . -name '*.cpp' -print0 | xargs --null grep /dev/null

This is still not perfect.  It might be a good idea to throw in a
"-type f" on the find, and there are probably many other little
tweeks one could do, but the idea is sound.

--Tim Smith

From: [email-masked]
Newsgroups: comp.os.linux.advocacy,comp.os.linux.misc
Subject: Re: Can grep work recursively?
Date: Thu, 31 Dec 1998 05:52:36 GMT
Organization: Deja News - The Leader in Internet Discussion

In article <[email-masked]>,
  [email-masked] wrote:
> I was wondering if it was possible to make grep work recursively in folders.
> Is this possible?

Try
find . -name "*" -exec grep whatever {} \;

where * is the wildcard for the files like *.txt etc
--
cheers
- Yendor

Date: Fri, 23 Jul 1999 19:02:11 -0700
From: Seth David Schoen <[email-masked]>
To: [email-masked]
Subject: Re: [svlug] find ./ print grep < it
X-Mailer: Mutt 0.95i

J C Lawrence writes:

> On Fri, 23 Jul 1999 13:06:45 -0700                                            
> George Georgalis <[email-masked]> wrote:                           
>                                                                               
> > Hi all, Maybe the subject line explains it... I never learned how           
> > to use print and exec with find and grep to search for a string in          
> > a directory tree...                                                         
>                                                                               
> For small directory trees:                                                    
>                                                                               
>   $ grep <pattern> `find . -type f`                                           
>                                                                               
> For larger trees:                                                             
>                                                                               
>   $ for file in `find . -type f`; do echo --- $file; grep <pattern>
>   $file;    
+done                                                                           
>                                                                               
> which gives the file names as it searches them as well as the                 
> matches.  The old                                                             
>                                                                               
>   $ find . -type f -exec grep <pattern>                                       
>                                                                               
> doesn't provide any filenames.                                                

You can

find . -type f -exec grep -l pattern '{}' ';' | xargs grep

or just

find . -type f -exec grep pattern /dev/null '{}' ';'

which is actually slightly more general (because it deals correctly with
two cases which the former doesn't).

If you prefer xargs to find -exec, you can save even more typing with

find . -type f | xargs grep pattern /dev/null

"foo | xargs bar" is likely to cause fewer problems than "bar `foo`"
for large amounts of output from foo (especially if you use "xargs -n").
--
                    Seth David Schoen <[email-masked]>
      They said look at the light we're giving you,  /  And the darkness
      that we're saving you from.   -- Dar Williams, "The Great Unknown"
  http://ishmael.geecs.org/~sigma/  (personal)  http://www.loyalty.org/ (CAF)

From: "Jeffrey B. Siegal" <[email-masked]>
Subject: Re: [svlug] How to find the biggest files?                
To: Dave Livingstone <[email-masked]>        
Cc: [email-masked]
X-Mailer: Mozilla 4.7 [en] (WinNT; U)         

Dave Livingstone wrote:
> Stupid question... once someone showed me how to find the biggest
> files on a
> partition. I cant seem to find it on any web pages/how to pages out
> there.
> Any guesses?

find . -type f -print0 | xargs -0 ls -s | sort -n

Date: Fri, 30 Aug 2002 09:29:19 +0100
From: Padraig Brady <[email-masked]>
Organization: Corvil Networks
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1) Gecko/20020827
To: David Neary <[email-masked]>
CC: "[email-masked]" <[email-masked]>
Subject: Re: [ILUG] Looking for a file / directory in zip file

David Neary wrote:
> Justin MacCarthy wrote:
>
>>Is there a way to look for a particular file or directory in 100's of zip
>>files??
>>Something like zgrep but for the filename instead of a word
>
> What does this have to do with ADSL (for thise like me with
> threaded mail readers)? Could you start off a new thread when
> you're starting off a new topic - I almost deleted your mail
> along with the rest of the thread.
>
> In any case, do you mean that you have lots of zip files, and you
> want to find a particular one, or that you have lots of zip
> files, and you want to find which zip files contain a particular
> filename? For the former, you can use find(1) as in
> find /path/to/zipfiles -name "myzipfile.zip" -print
>
> For the latter,
> find /path/to/zipfiles -name "*.zip" -exec unzip -l {} | grep \
> 'myfile' \;
> or
> find /path/to/zipfiles -name "*.zip" -print0 | xargs -0 unzip \
> -l {} | grep 'myfile' \;

bzzt.
This will tell you the filenames are present but not what zip file
they're in. You need something like:

find /path/to/zipfiles -name "*.zip" -print0 | xargs -r0 -i unzip \
-l "{}" | grep -E '(^Archive|myfile)'

This is noisy though (i.e. not general). There should be a new
print mode x for `unzip -Zx` where the zipname is printed like:
zipname: myfile
Then you could easily grep/process this.

P=E1draig.

From: "Brian Sroufek" <[email-masked]>
To: [email-masked]
Subject: [Balug-talk] linux/unix search command/tool/utilities
Date: Fri, 06 Sep 2002 21:08:02 -0400

[begin Xli quotation:]

Hi,

what command/tool/utility in linux/unix that I can use
to do a search, and recursively, and show all the
files that have the search pattern ? I don't mean
ctags, cuz it only goes to the definitions. I am
looking for that similar to windows search where it
will list all the files that contains the pattern.

Thanks
Xli
[begin Xli quotation:]

find [path] -type f -exec grep -l 'pattern' {} \;

Brian Sroufek