linuxtextgrepdirectoryfind

Find all files containing a specific text (string) on Linux?


How do I find all files containing a specific string of text within their file contents?

The following doesn't work. It seems to display every single file in the system.

find / -type f -exec grep -H 'text-to-find-here' {} \;

Solution

  • Do the following:

    grep -rnw '/path/to/somewhere/' -e 'pattern'
    

    Along with these, --exclude, --include, --exclude-dir flags could be used for efficient searching:

    This works very well for me, to achieve almost the same purpose like yours.

    For more options, see man grep.