1752720 Members
5663 Online
108789 Solutions
New Discussion юеВ

Unix Grep

 
jilpangs
Occasional Advisor

Re: Unix Grep

Hi,

I'm not sure which file would have the string which i'm searching for. Hence i'm planning to start the search from my home directory.

Thats why i couldnt "Limit to set of directory"

How can limit to set of directory ?

Thanks
Jil
A. Clay Stephenson
Acclaimed Contributor

Re: Unix Grep

find /dir1 /dir2 /dir3/xxx -type f ...

This will sequentially search /dir1 (and all subdirectories) then /dir2 (abd subdirectories) then /dir3/xxx and so on.


Man find for details.

If you are unsure, then you can simply find / but be aware of the load you are imposing on the system.
If it ain't broke, I can fix that.
Philip Kernohan
Advisor

Re: Unix Grep

jilpangs,

I use something similar to this when I'm looking for a text string in a list of directories. You obviously need the correct search/read permissions to do this:

find . -follow -type f \( -name '*.sql' -o -name '*.sh' -o -name '*.log' \) -exec grep -il '' {} \; 2>/dev/nu

find
. :from this direction

-follow :follow all symbolic links

-type f :find only regular files

\( -name ... -o \) :matching an OR of these regular expressions

-exec :execute the following command

grep -il '' :grep all find results for regular expression, ignore case and print filenames to stdout

2>/dev/null :stderr to /dev/null

You can place this is a 'for' loop to execute more commands on the resulting files.

Regards,
PK
It's nice to be important but it's more important to be nice
Hein van den Heuvel
Honored Contributor

Re: Unix Grep


Do you need to 'see' the matches, or just know which files might match. Fo rthe latter:

find . -type f \( -name '*.sql' -o -name '*.sh' -o -name '*.log' \) -exec grep -l "ADFH Script Failed" {} \;

Hein.