grep: Binary file matches

Fix 'Binary file (standard input) matches' when grep detects non-text content in the searched file.

grep produces "Binary file (standard input) matches" when it detects non-text (binary) bytes in the input and suppresses the output to prevent garbled terminal display.

What Causes This Message

The file contains null bytes ( \x00) or other non-printable characters that grep interprets as binary content. Log files with embedded binary data, files with mixed encodings, and files incorrectly detected as binary all trigger this message.

How to Fix

  1. Force grep to treat the file as text:
grep -a "pattern" /path/to/file

The -a (or --text) flag forces grep to process the file as ASCII text regardless of content.

  1. Skip binary files entirely during recursive searches:
grep -rI "pattern" /var/log/

The -I flag (equivalent to --binary-files=without-match) silently skips binary files.