Search all files in a folder tree

What is the command line input to search for a word in a folder tree, in other words, in all the files in all the folders under a specified folder.
bob1010Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mmarthaCommented:
find /path/where/you/want/to/look -name "word"               for looking for a filename. (you can use wildcards)
0
nochkinCommented:
If you are looking for this word inside of your files (contents) then you can do the following:

find /path/to/your/folder -exec grep -l "word" {} \;

That will give you a list of files which contains your "word" inside starting with /path/to/your/folder and deeper.
If you want to filter and check inside of *.txt files then you can do like this:

find /path/to/your/folder -name "*.txt" -exec grep -l "word" {} \;

That willd do the same thing, but will search in *.txt files only in all subdirectories starting with /path/to/your/folder and deeper.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
yuzhCommented:
find /path/to/your/folder  -type f | xargs grep -l "word"

man find
man xargs
to learn more details
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

brettmjohnsonCommented:
This is the Linux forum, and Linux uses gnu grep which supports recursive search.
So you can simply do:

grep -r "word" /path/to/your/folder

0
stefan73Commented:
Depending whether you're looking for an entire word, you could also use the -w option, perhaps paired with -i:

find folder -type f | xargs grep -wil word
0
avatechCommented:
Most linux installs also have the find-utils and updatedb installed by default.  You can use these for simple file name searching and pipe the results through grep =)  If you are looking for keyword dearches within the files then someone above already covered the recursive grep.  Otherwise if just searching for file names, you may have to first make sure that updatedb (run as root) has been run recently and it will create a file table database.  I think that SuSE and Redhat by default ran the updatedb every night at midnight in a cron ... but if not take a minute to run updatedb as root.  Once it's done, here are some eample searches:

locate *.doc | grep "path/you/want"
locate word
locate word | grep "/specific/path/to/list"

You can use pattern matching like "locate file*" or "locate *file*" or even "locate *.xl?"

Hope that helps!

Dean
0
The--CaptainCommented:
Are you looking for files whose names match a particular string, or files that *contain* a particular string?  The "solutions" above are mixed regarding this, and require clarification...

Cheers,
-Jon

0
soldatoCommented:
find / *.zip

would be an example
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.