find files containing a text

Search every file under a folder for a word or a phrase, and show where it is.

  • files
  • text
  • search

Steps

  1. grep -rn 'some text' .

    every line containing the text, under this folder, with file and line number

  2. grep -rl 'some text' .

    only the names of the files that contain it

  3. grep -rni 'some text' .

    the same, ignoring upper and lower case

  4. grep -rnw 'word' .

    only where it is a whole word

  5. grep -rn --include='*.py' 'some text' .

    only in the files of one kind

  6. grep -rn --exclude-dir={.git,node_modules} 'some text' .

    skipping folders you do not want searched

  7. rg 'some text'

    the same, faster, with ripgrep, which skips what .gitignore lists

Notes

  • -I skips binary files, and 2>/dev/null hides the files you may not read.

Commands used

  • grep
  • rg
  • find

Each has a page in lore: lore grep opens it.