[SWLUG] Any tips on locating this file.

pbhj pbhj at hotmail.com
Thu Aug 19 13:26:30 UTC 2004


How about:

grep -H -e wordToFind -f ./*

this just from reading "man grep", I often use this kind of thing (hope 
I got the command line right as I'm in windows at the mo') when I'm 
trying to find where in the initialisation scripts something is loaded 
-- I'm on Slackware 10. The H makes the returns list the filename, you 
can add context and line numbers with other switches (which I can't 
remember). The -e starts the regular expression. You can also have line 
number from the start of the file, which is handy for source code searching.

Using find as well or piping anything seems, to me, a bit complicated 
for this.

Cheers

Paul

Carter N. wrote:

>Hi all,
>
>  
>
>>What I need is either a way of searching all files for the string. which is
>>    
>>
>
>  
>
>>Perhaps some kind of permuation on the find command?
>>    
>>
>
>There are a variety of ways of applying commands, such as grep, to specified
>files, including sub-directories. Some are based on the xargs and find
>commands.
>
>looking for all mentions of a variable named counter in source code files,
>which have names ending in .c ...
>
>
>Using xargs:
>
>    find ./ -name '*.c' | xargs grep counter
>
>This is equivalent to:
>
>    grep foo `find ./ -name '*.c'`
>
>The following will print the filenames of the files containing foo.
>
>    find ./ -name '*.c' | xargs grep -l foo
>
>
>Using find's -exec option...
>
>    find ./ -name '*.c' -exec grep foo {} \;
>
>The -exec method tends to be slower because grep is executed once per file
>found. If the command to be executed (in this case grep) can take multiple
>files as an argument, the xargs and reverse-quotes methods are faster. This
>is because grep is executed only once (with the concatenation of the files
>found) instead of many times. This is especially true when recursing into a
>big directory structure.
>
>The advantage of the exec method is that if it returns 0 (found) then any
>subsequent arguments are also evaluated. To print the names of matched
>files:
>
>    find ./ -name '*.c' -exec grep foo {} \; -print 
>
>
>Hope this helps.
>
>Neil
>--------------------------------------------
>Neil Carter            Psychology Department
>IT Technician    University of Wales Swansea
>                       Wales, United Kingdom
>
>http://psy.swansea.ac.uk/staff/Carter/
>
>
>_______________________________________________
>SWLUG Discussion List - Discuss at swlug.org.uk
>http://list.swlug.org.uk/mailman/listinfo/discuss
>
>.
>
>  
>




More information about the Swlug mailing list