Bash Grep Subdirectories (Recursively)

by Vivek Gite on February 17, 2007 · 0 comments

How do I recursively grep through all sub-directories and find files containing given text / string or words?

You can use the -r option to recursively grep through all sub-directories and find text. The syntax is as follows:

grep -r "text" /path/to/di

In this example, search for an IP 192.168.1.254 in through all /etc/ and all its sub-directories:

grep -r "192.168.1.254" /etc/

Search in any case:

grep -ri "letters" /home/vivek/data

Use the -l switch to display only the names of files in which the text occurs:

grep -lri "foo" /data

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 5 + 3 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: