How to find all files containing a specific text in Linux?

Home forums Unix and Linux How to find all files containing a specific text in Linux?

Tagged: , ,

This topic contains 0 replies, has 1 voice, and was last updated by  Hemant Sharma 4 months, 2 weeks ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #2216

    Hemant Sharma
    Moderator

    If you want to do a recursive search and return the line number of found results, grep is best choice.

    This is the basic syntax for doing recursive (r ) , Line number (n) and whole word (w) search for pattern.

    grep -rnw ‘/some/path/dir/’ -e ‘pattern’

    the search can be refined with additional options to include and exclude file and directories.

    –exclude *.log
    –include *.sh
    –exclude-dir /usr/lib
    –include-dir /usr/local

    for example
    grep –exclude *.log -rnw ‘/some/path/dir/’ -e ‘pattern’

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.