Finding all files containing a text string on linux

I faced with the issue that how to find all files containing a text string on linux

Just t do the following steps (I copy and paste from stackoverflow.com)

-r is recursive, -n is line number and -w stands match the whole word. Along with these, –exclude or –include parameter could be used for efficient searching. Something like below:

This will only search through the files which have .c or .h extensions. Similarly a sample use of –exclude:

Above will exclude searching all the files ending with .o extension. Just like exclude file it’s possible to exclude/include directories through –exclude-dir and –include-dir parameter, the following shows how to integrate –exclude-dir:

This works well for me.

References:
http://stackoverflow.com/questions/16956810/finding-all-files-containing-a-text-string-on-linux http://www-users.york.ac.uk/~mijp1/teaching/2nd_year_Comp_Lab/guides/grep_awk_sed.pdf ( useful tutorial about grep awk and sed command line)

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.