Monday, August 6, 2018

How to Grep files in Linux, but only certain file extensions?


Want to search your file system on Linux?  It's easy!

    grep -r --include=\*.txt 'searchterm' ./

...or case-insensitive version...

    grep -r -i --include=\*.txt 'searchterm' ./
  • grep : command
  • -r : recursively
  • -i : ignore-case
  • --include : all *.txt: text files (escape with \ just in case you have a directory with asterisks in the filenames)
  • 'searchterm' : What to search
  • ./ : Start at current directory.

1 comment: