Find All Files Containing A Given String

Last modified: 
Tuesday, March 31st, 2015

Using Grep to Locate Files Which Contain a Given String

grep -r string directory

An Example

# Create some example files in /tmp
cd /tmp
mkdir grepexample
cd grepexample/
mkdir dir
touch a.txt
touch b.txt
echo '@TODO' > c.txt
echo '@TODO' > dir/e.txt
touch dir/f.txt
echo '@TODO Has some text on this line' > dir/g.txt

# Recurisively search for all the files containing '@TODO'
grep -r @TODO /tmp/grepexample
/tmp/grepexample/c.txt:@TODO
/tmp/grepexample/dir/e.txt:@TODO
/tmp/grepexample/dir/g.txt:@TODO Has some text on this line


The operator of this site makes no claims, promises, or guarantees of the accuracy, completeness, originality, uniqueness, or even general adequacy of the contents herein and expressly disclaims liability for errors and omissions in the contents of this website.