Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fgrep 2

Status
Not open for further replies.

we2aresame

Technical User
Feb 10, 2003
128
CA
how to use fgrep to figure out all files which include a special word?
for example:
fgrep hello /etc/inittab, can get hello from /etc/inittab, now I try to get hello from all files on my server, thanks.
 
Try this:

find / -print |xargs fgrep "mystring"

It's going to take a while, though.
 
If you do not need the lines containing the specified word, you should add a -c option to the grep. This prints only the match count per file. Then you can filter unneded entries:

find / -type f | xargs grep -c "mystring" | grep -v ":0$"

"-type f" is necessary for "find", because if you miss it, grep will try to filter directory files, fifos, character specials and any else.
grepping a fifo may last veeeeery looooong :)

--Trifo
 
I use:

find / -type f -xdev | xargs grep -i "STRING" 2>/dev/null


or : find / -name "*.log" -print -exec grep -i "STRING" {} \;

I use "-xdev" to avoid searchig on Filesystems other then this one.
Use 2>/dev/null to avoid getting plenty of error messages on protected files/dirs.


"Long live king Moshiach !"
 
Yes, "-type f" is necessary, otherwise, the process maybe run for days, thanks all.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top