1831008 Members
21756 Online
110018 Solutions
New Discussion

find a string

 
Ali Syed Masoud
Advisor

find a string

How to find a string in a any file in any directory ?

Actually what happened is that a post exec script failed because of a wrong directory specified on an unknown script.
i know what is that directory

Need help.
13 REPLIES 13
Steve Steel
Honored Contributor

Re: find a string

Hi


Find . -type f|xargs grep -il string


Will give the name of all files where the
string ocurs relative to the current directory.


steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Jose Mosquera
Honored Contributor

Re: find a string

Hi,

#find -type f -exec grep -l '' \;

This command let you search into a specific through regular file type a specific char string specified in

Rgds.
Trond Haugen
Honored Contributor

Re: find a string

Another option if you know the directory is:
cd
grep *

Regards,
Trond
Regards,
Trond Haugen
LinkedIn
KapilRaj
Honored Contributor

Re: find a string

grep 'string' *

kaps
Nothing is impossible
Ali Syed Masoud
Advisor

Re: find a string

the following doesnt work !

find -type f -exec grep -l '' \;

regards,
ali.
Trond Haugen
Honored Contributor

Re: find a string

Could you be more spesific.
Exactly what do you type and what do you get.

Regards,
Trond
Regards,
Trond Haugen
LinkedIn
James R. Ferguson
Acclaimed Contributor

Re: find a string

Hi:

This will work:

# find /dir -type f -print|xargs grep yourstring

...the use of 'xargs' is also less resource-intensive than 'exec'. Notice the addition of the '-print' option to 'find' to output the filenames.

Regards!

...JRF...
john korterman
Honored Contributor

Re: find a string

Hi,
you need to include curly braces in the command string: The file names, in which the grep command will search, will be put in there, e.g.:

find -type f -exec grep -l '' {} \;

else grep will just hang.

regards,
John K.
it would be nice if you always got a second chance
Jose Mosquera
Honored Contributor

Re: find a string

Hi again,

This command works fine! Let try be too explicit. Supose that you need search the "loopback" string into your "/etc" directory, the sintax must be:

#find /etc -type f -exec grep -l 'loopback' {} \;

In my case the string "loopbak" was found in:
/etc/hosts
/etc/services
/etc/rc.config.d/netconf
/etc/hpC2400/arraymon.dest
/etc/opt/resmon/log/client.log
/etc/netconfig
/etc/ppp/Dialers.ex
/etc/networks
/etc/sam/reg_tm.db
/etc/#hosts

Rgds.
K.Vijayaragavan.
Respected Contributor

Re: find a string

If you want to search for the ocurance of the string "CPU" in any files in the system, then you can use the command,

# find / -type f | xargs grep "CPU"
"Let us fine tune our knowledge together"
Paul Sperry
Honored Contributor

Re: find a string

cd /
find . -print | xargs grep *
Ali Syed Masoud
Advisor

Re: find a string

find / -type f | xargs grep "CPU"

find /etc -type f -exec grep -l 'loopback' {} \;

the above both work really fine

thanks everybody.

ali.
Trond Haugen
Honored Contributor

Re: find a string

If you are happy with the answers you should assign points accordingly.

Regards,
Trond
Regards,
Trond Haugen
LinkedIn