how to search every subdirectory and find a string?

how to search every subdirectory and find a string?

Post by yhuan » Fri, 07 Apr 2000 04:00:00



Hello Unix experts,

How can I search a string from every file in every
subdirectory? I can search a string by using grep command,
but it is only for the files in the current directory,
anyway I can go down to subdir? I tryed to use pipe, but did
not work.

Thanks in advance for your help

Y Huang

* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping.  Smart is Beautiful

 
 
 

how to search every subdirectory and find a string?

Post by Charles Dem » Fri, 07 Apr 2000 04:00:00




>Hello Unix experts,

>How can I search a string from every file in every
>subdirectory? I can search a string by using grep command,
>but it is only for the files in the current directory,
>anyway I can go down to subdir? I tryed to use pipe, but did
>not work.

I suggest you use find and xargs along with grep, something
like this:

find ./ | xargs grep 'your-string-here' /dev/null

Be careful, this can produce a lot of output if there are a lot of
matches.

man find
man xargs
man grep

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.


 
 
 

how to search every subdirectory and find a string?

Post by faraz hussai » Fri, 07 Apr 2000 04:00:00


find ./ | grep 'your-string-here'

or make a script called f and put this in it:

find ./ | grep $1

and use it like this:

f 'your string here'

 
 
 

how to search every subdirectory and find a string?

Post by Chris Costell » Fri, 07 Apr 2000 04:00:00



> find ./ | grep 'your-string-here'

   That will only match file _names_ not actual files.  The
article you responded to had the correct solution.


 
 
 

how to search every subdirectory and find a string?

Post by Bit Twist » Fri, 07 Apr 2000 04:00:00


Might try something like
        man find         then something to play with

find  . -name "*.h" | xargs grep string_2_find

On Thu, 06 Apr 2000 10:31:30 -0700, yhuang


>Hello Unix experts,

>How can I search a string from every file in every
>subdirectory? I can search a string by using grep command,
>but it is only for the files in the current directory,
>anyway I can go down to subdir? I tryed to use pipe, but did
>not work.

--
The warrenty and liability expired as you read the message.
If the above breaks your system, it's yours and you keep both pieces.
Practice safe computing. Backup the file before you change it.
Do a,  man every_command_here, before doing anything or running a script.
 
 
 

how to search every subdirectory and find a string?

Post by Mitc » Sat, 08 Apr 2000 04:00:00


When was it, ... er.. oh, yes, on Thu, 06 Apr 2000 10:31:30 -0700,
erm, whassname, ah... oh, aye, that yhuang

um.. oh, something like:

Quote:>   How can I search a string from every file in every
>   subdirectory? I can search a string by using grep command,
>   but it is only for the files in the current directory,
>   anyway I can go down to subdir? I tryed to use pipe, but did
>   not work.

find . -print | xargs grep "string2find"

rgds,
mitch

    _____ __ ______ ______ __ _
   /      \__\      \ ____>  < \  Currently Listening
   \ \  / /  /_\  /_/     \     \ To:  Awake
    >_><_<\_/  /__\ \_____/__<__/     Dream Theatre