anyone know of a recursive/cascade 'grep' utility in Linux?

anyone know of a recursive/cascade 'grep' utility in Linux?

Post by michael thoma » Sat, 26 Jan 2002 04:35:11



Hi all,

I want to grep through all the files in a directory (in order to find a
specific string within each and every file) and then continue grepping
through the sub-directories below the current directory. Kind of like a
CASCADE GREP

Thanks!

Michael

 
 
 

anyone know of a recursive/cascade 'grep' utility in Linux?

Post by Grant Edwar » Sat, 26 Jan 2002 04:54:08



> Hi all,

> I want to grep through all the files in a directory (in order to find a
> specific string within each and every file) and then continue grepping
> through the sub-directories below the current directory. Kind of like a
> CASCADE GREP

recent versions of grep have a '-r' option that does what you
want:

 $ grep -r string .

--
Grant Edwards                   grante             Yow!  Where's th' DAFFY
                                  at               DUCK EXHIBIT??
                               visi.com            

 
 
 

anyone know of a recursive/cascade 'grep' utility in Linux?

Post by el.. » Sat, 26 Jan 2002 05:11:52




>I want to grep through all the files in a directory (in order to find a
>specific string within each and every file) and then continue grepping
>through the sub-directories below the current directory. Kind of like a
>CASCADE GREP

You can use grep's -r option.  You can also use find and
xargs:

  find | xargs grep yourstring

--
http://www.spinics.net/linux/

 
 
 

anyone know of a recursive/cascade 'grep' utility in Linux?

Post by Ivan Molell » Sat, 26 Jan 2002 06:24:29


If there are not too many files in all subdirectory,you can try:

    grep string  'find . -name "*" '

--
Ivan Molella

__LINUX__ the choice of the  __GNU__ generation

 
 
 

anyone know of a recursive/cascade 'grep' utility in Linux?

Post by Frank Sied » Sat, 26 Jan 2002 06:40:07


or try the classic style:

find . -name "*" -exec grep "yourstring" /dev/null {} \;

We have a script called "fw"  installed on all our unix development systems

#fw.script
find . -name "*.[ch]" -exec grep $1 /dev/null {} \;



Quote:> Hi all,

> I want to grep through all the files in a directory (in order to find a
> specific string within each and every file) and then continue grepping
> through the sub-directories below the current directory. Kind of like a
> CASCADE GREP

> Thanks!

> Michael

 
 
 

anyone know of a recursive/cascade 'grep' utility in Linux?

Post by el.. » Sat, 26 Jan 2002 07:27:25




>or try the classic style:

>find . -name "*" -exec grep "yourstring" /dev/null {} \;

Wouldn't that invoke a seperate grep for every file?

--
http://www.spinics.net/linux/

 
 
 

anyone know of a recursive/cascade 'grep' utility in Linux?

Post by Kasper Dupon » Sat, 26 Jan 2002 08:10:18





> >or try the classic style:

> >find . -name "*" -exec grep "yourstring" /dev/null {} \;

> Wouldn't that invoke a seperate grep for every file?

I think so. Combining find, xargs, and grep would probably
be more efficient. I use this alias:
alias finds='find `/bin/pwd` -type f -print0 | xargs -0 grep'
(I don't remember how I came up with the name for that alias.)

--
Kasper Dupont

 
 
 

anyone know of a recursive/cascade 'grep' utility in Linux?

Post by Bob Tenne » Sat, 26 Jan 2002 09:04:30


 >
 > I want to grep through all the files in a directory (in order to find a
 > specific string within each and every file) and then continue grepping
 > through the sub-directories below the current directory. Kind of like a
 > CASCADE GREP

Install glimpse. Finds anything anywhere (using an index of course).

Bob T.

 
 
 

anyone know of a recursive/cascade 'grep' utility in Linux?

Post by Eric P. McC » Sat, 26 Jan 2002 10:47:32



> If there are not too many files in all subdirectory,you can try:
>     grep string  'find . -name "*" '

1. The limit is on the length of the command line, not the number of
   files in the directory.
2. You mean `find . -name '*'` (note backticks instead of regular
   apostrophes).

--

"I woke up this morning and realized what the game needed: pirates,
pimps, and gay furries."  - Rich "Lowtax" Kyanka

 
 
 

anyone know of a recursive/cascade 'grep' utility in Linux?

Post by Eric P. McC » Sat, 26 Jan 2002 10:55:15



> I want to grep through all the files in a directory (in order to find a
> specific string within each and every file) and then continue grepping
> through the sub-directories below the current directory. Kind of like a
> CASCADE GREP

You need to experience the magic of `find' and `xargs'.  This will do
what you want:

  % find . -type f -print0 | xargs -0 grep <search>

See the man pages for more information on both, since both commands
can do a lot of really slick things (like `find'ing based on
practically any imaginable file characteristic, and job control on
what `xargs' runs).

--

"I woke up this morning and realized what the game needed: pirates,
pimps, and gay furries."  - Rich "Lowtax" Kyanka

 
 
 

anyone know of a recursive/cascade 'grep' utility in Linux?

Post by el.. » Sat, 26 Jan 2002 13:21:10




Quote:>> If there are not too many files in all subdirectory,you can try:
>>     grep string  'find . -name "*" '
>1. The limit is on the length of the command line, not the number of
>   files in the directory.

Not having "too many files" keeps this command from overflowing
the command line.  

--
http://www.spinics.net/linux/

 
 
 

anyone know of a recursive/cascade 'grep' utility in Linux?

Post by Eric P. McC » Sun, 27 Jan 2002 02:30:05



> >> If there are not too many files in all subdirectory,you can try:
> >>     grep string  'find . -name "*" '
> >1. The limit is on the length of the command line, not the number of
> >   files in the directory.
> Not having "too many files" keeps this command from overflowing
> the command line.  

No, because you might have a small number of files with extremely long
names.

The way the warning is written originally implies that the limit is on
the number of files, which might confuse a new user when he discovers
that it's taking a different number of files to cause an error.
Practically speaking, you're right, of course; but I think we should
endeavor to be completely correct when answering questions.

--

"I woke up this morning and realized what the game needed: pirates,
pimps, and gay furries."  - Rich "Lowtax" Kyanka

 
 
 

anyone know of a recursive/cascade 'grep' utility in Linux?

Post by R Smit » Sun, 27 Jan 2002 15:10:54



> Hi all,

> I want to grep through all the files in a directory (in order to find a
> specific string within each and every file) and then continue grepping
> through the sub-directories below the current directory. Kind of like a
> CASCADE GREP

> Thanks!

> Michael

I currently do it like so...
find /usr/src/linux/ -name '*.c' -print | xargs grep 'generic_file_llseek'
---
 
 
 

anyone know of a recursive/cascade 'grep' utility in Linux?

Post by Philip Armstro » Sun, 27 Jan 2002 19:08:37





>> I want to grep through all the files in a directory (in order to find a
>> specific string within each and every file) and then continue grepping
>> through the sub-directories below the current directory. Kind of like a
>> CASCADE GREP
>I currently do it like so...
>find /usr/src/linux/ -name '*.c' -print | xargs grep 'generic_file_llseek'

Bonus points for using xargs to reduce the number of invocations of
grep.

However, with GNU grep you can do:

$ grep -d recurse "search text" /usr/src/linux/*

which will DTRT.

cheers,

Phil

--
http://www.kantaka.co.uk/ .oOo. public key: http://www.kantaka.co.uk/gpg.txt

 
 
 

anyone know of a recursive/cascade 'grep' utility in Linux?

Post by el.. » Mon, 28 Jan 2002 12:47:58




>>I currently do it like so...
>>find /usr/src/linux/ -name '*.c' -print | xargs grep 'generic_file_llseek'
>Bonus points for using xargs to reduce the number of invocations of
>grep.

>However, with GNU grep you can do:

>$ grep -d recurse "search text" /usr/src/linux/*

But that won't restrict grep to using *.c files.

--
http://www.spinics.net/linux/

 
 
 

1. Available: Recursive 'file' Type Report Utility


#------------------------------------------------------------------------
#
#  NAME
#
#     dfile - Recursive 'file' command with 'file' output editing
#
#  SYNOPSIS
#
#     dfile [ -c -r ] directory [ ... ]
#
#  DESCRIPTION
#
#     Attempts to apply suffix rules to the 'file' command output
#     for each file in directory.  It displays suffixes, where applicable
#     as well as an edited 'file' command output.  In some cases
#     groups files by entire file names (ie. README, [M|m]akefile, core).
#
#     It is easy to expand/change the suffix-filtering rules which are
#     embedded 'sed' edits.  The 'sed' editing commands are in the
#     'create_sed_edits()' function.
#
#     Three (3) Intermediate 'tee' files are created and can be retained.
#
#     Three (3) 'sed' edit command files are created and can also be
#     retained in 'test' mode.
#
#     Displays count summations by file 'type'.
#
#     Developed under Cygwin/bash, but should be fairly portable
#     (especially to linux) since nothing REALLY bizarre was coded.
#
#  OPTIONS
#
#    '-c' Sorts output on the file 'count' column rather than
#         than the file 'type' column (the default).
#
#    '-r' Reverses sort order on current 'sort' column (count or type).
#
#  ENVIRONMENT VARIABLES
#
#     SH_TEST set to any value will create 'tee' and 'sed' files
#             in CWD instead of /tmp and defer removal of
#             these 'tee' and 'sed files upon program exit.
#
#  BUGS
#
#     The recognized suffixes are limited to only a few hundred.
#     These should be expanded.  Please feel free ...
#    
#     Fails miserably in MSDOS file systems ... probably due to
#     spaced-out file names.  Should be OK on a *ix machine.
#
#  SEE ALSO
#
#     file(1), tee(1), uniq(1), sort(1)
#
#

#                                      Include 'techalert' in Subject
#
#------------------------------------------------------------------------

2. rewriteMap in apache dies when mysql used..? help!

3. Availability: Recursive 'file type' Report Utility

4. TIME_WAIT, CLOSE_WAIT connection states

5. grep octal value (grep '\0145' /tmp/test) doesn't work !!

6. getty-less system?

7. sag utility gives a 'terminal type not known' error

8. conditional Makefile

9. Know of a sh 'tree' utility?

10. recursive grep'ing

11. How to make grep select both lines using only a single 'grep' command

12. Does anyone know if 'top' is still being maintained?

13. Scripts for adding users - does anyone know 'sam'?