`grep ERROR /var/log/app/app.log` prints only `grep: /var/log/app/app.log: binary file matches`.
BeginnerTroubleshootingTroubleshooting: tools, portability, permissions and environment
Answer
Likely causes → The log contains NUL bytes or invalid UTF-8 (a crash mid-write, a binary payload logged by mistake, or a file preallocated with zeros after a copytruncate), so GNU grep treats it as binary and suppresses matching lines.
Diagnose →
grep -c $'\x00' /var/log/app/app.log 2>/dev/null; tr -d '\000' < /var/log/app/app.log | wc -l
grep -naP '\x00' /var/log/app/app.log | head -3 # where the NULs are (GNU grep)
Fix → Force text mode, optionally stripping NULs:
grep -a ERROR /var/log/app/app.log
tr -d '\000' < /var/log/app/app.log | grep ERROR
Prevent → Use -a in scripts that grep logs, and fix the root cause: copytruncate with an app that does not open the file in append mode leaves a sparse, NUL-filled prefix; switch to postrotate with a reopen signal.
More on Troubleshooting: tools, portability, permissions and environment
On a Mac, `sed -i 's/replicas: 2/replicas: 3/' deploy.yaml` fails with `sed: 1: "deploy.yaml": extra characters at the end of d command`.BeginnerA cleanup script fails on a developer's Mac with `date: illegal option -- d`.BeginnerA script that works on Ubuntu fails in an Alpine-based CI image with `grep: unrecognized option: P`.IntermediateAn `awk` one-liner works on your RHEL box but fails on Ubuntu with `awk: line 1: function gensub never defined`.Intermediate`comm -23 expected.txt installed.txt` prints `comm: file 1 is not in sorted order`, even though both files were produced with `sort`.IntermediateOn macOS, `tr '[:lower:]' '[:upper:]' < export.csv` fails with `tr: Illegal byte sequence`, and `sed` gives `sed: RE error: illegal byte sequence`.Intermediate