Find text inside files using Terminal on Linux or Mac OSX

Use grep to search for some particular text inside files and folders recursively.

$ grep -rnw '/path' -e 'search term'
# Backticks to use pwd /src as the search target
$ grep -rnw `pwd`/src -e 'search term'
  • -r is recursive,
  • -n is line number
  • -w is to match the whole word

Note: the path is not relative to your current directory, so you may wish to use ‘pwd’ to display your current directory path and copy paste this in as the path.

Leave a Reply

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