Linux `grep` Stopped Printing Lines (`Binary file matches`)

Log file contained a stray NUL (`\x00`) byte causing GNU grep to treat it as binary.

Runs locally in browser Free · No login Independently Verified 2026-11-25 v4.1.0
Identifier: Linux `grep` Stopped Printing Lines (`Binary file matches`) Platform: Linux
Common Root Causes:
  • Log file contained a stray NUL (`\x00`) byte causing GNU grep to treat it as binary.

Interactive Diagnostic Checklist

Verified Solutions:
  1. Pass `grep -a` (`--text`) to force text scanning across logs with stray null bytes.
Safe Diagnostic Command:
file <logfile>
Warning: Verify configuration changes in staging or with dry-run flags (e.g. nginx -t) before reloading production services.

Technical Explanation

Log file contained a stray NUL (`\x00`) byte causing GNU grep to treat it as binary. Recommended diagnostic: `file <logfile>`. Remediation: Pass `grep -a` (`--text`) to force text scanning across logs with stray null bytes.

Worked Examples

  • Run `file <logfile>` to verify root cause before applying the remediation.

Limitations & Assumptions

  • Always verify configuration changes in staging or with dry-run flags (e.g. `nginx -t`) before reloading production services.

Source References & Verification

Resource ID: err-linux-grep-binary-file-matches · Independently verified: 2026-11-25

Related Resources