0

Linux - How do I search all non-binary (text) files recursively for a certain string

  • search all files for a string
  • skip binary
  • recursively
  • list filenames
  • (and if possible echo the line + line number of the filename where it was found as option)

I was looking at Bash: passing braces as arguments to bash function and How to search for a string only in textfiles? (recursively)

But did not find an answer, only discussion

2

With GNU grep, adding the following options:

  • -F or --fixed-strings
  • -I or --binary-files=without-match
  • -r or --recursive
  • this is the default when using -r, but may be made explicit with -H or --with-filename
  • -n or --line-number

So

grep -FIrn string .

See man grep.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.