Link to home
Start Free TrialLog in
Avatar of bob1010
bob1010

asked on

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.
Avatar of mmartha
mmartha

find /path/where/you/want/to/look -name "word"               for looking for a filename. (you can use wildcards)
ASKER CERTIFIED SOLUTION
Avatar of nochkin
nochkin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yuzh
find /path/to/your/folder  -type f | xargs grep -l "word"

man find
man xargs
to learn more details
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

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
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
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

find / *.zip

would be an example