Find Files Containing a Text String (Linux)

There are multiple ways to find files containing a text string. Here is one simple command (grep) to achieve the goal.

grep -ril "texthere" directory

find command is also recommend because of speed and ability to deal with filenames that contain spaces.
find . -type f -exec grep -l "foo" {} +

Older UNIX version can use xargs to speed up the search:
find /path/to/dir -type f | xargs grep -l "foo"

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on RedditShare on StumbleUponEmail this to someoneShare on TumblrDigg this

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">