1833123 Members
3701 Online
110051 Solutions
New Discussion

Advanced Find

 
SOLVED
Go to solution
Scott McDade
Frequent Advisor

Advanced Find

I am trying to find a specific word, phase, or fragment that is contained within a file but I do not know what the file name is or directory what is the easiest way to accomplish this? And can you use wild cards?
Keep it Simple!~
4 REPLIES 4
Steffi Jones_1
Esteemed Contributor
Solution

Re: Advanced Find

Hi Scott,

one thing that comes to my mind is using the grep command.
If you are in a sepcific directory you can do the following:

# grep *

That will lokk for the word in all the files listed in that directory.

I used it too for the next level:

#grep */*

But that is the deepest you can run it.

Hope that helps a bit,

Steffi Jones
Robert Hoey
Advisor

Re: Advanced Find

Try the following commands:
# cd /
# find . -type f -print | xargs grep -i stringlookingfor /dev/null

This is usually what I use to find a particular string in a file. It may take a while to run, so if you have a guess of where the file is, change to that directory and then execute the find command, it may save some time. Also, you may want to write the output to file for easier viewing.

-Rob
Ron Cornwell
Trusted Contributor

Re: Advanced Find

for i in `ls -R`
do
grep
done
A. Clay Stephenson
Acclaimed Contributor

Re: Advanced Find

Hi Scott,

I have attached a utility that works pretty well. You cd to the desired directory to start searching.
Then enter find.sh target (target can be a substring and is not case sensitive). It then recursively descends from the current directory examining regular files which are also some form of text. Those files are then examined for the target string.

Clay
If it ain't broke, I can fix that.