<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Troubleshooting on Daniel Zhang</title><link>https://zhangdapeng.dev/tags/troubleshooting/</link><description>Recent content in Troubleshooting on Daniel Zhang</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Fri, 06 Nov 2026 08:00:00 +0800</lastBuildDate><atom:link href="https://zhangdapeng.dev/tags/troubleshooting/index.xml" rel="self" type="application/rss+xml"/><item><title>How to Fix grep: Binary File Matches When Searching Linux Logs</title><link>https://zhangdapeng.dev/p/grep-binary-file-matches-linux/</link><pubDate>Fri, 06 Nov 2026 08:00:00 +0800</pubDate><guid>https://zhangdapeng.dev/p/grep-binary-file-matches-linux/</guid><description>&lt;img src="https://zhangdapeng.dev/p/grep-binary-file-matches-linux/grep-binary-file-matches-linux.png" alt="Featured image of post How to Fix grep: Binary File Matches When Searching Linux Logs" /&gt;&lt;p&gt;When troubleshooting server errors, developers frequently rely on &lt;code&gt;grep&lt;/code&gt; to search application logs. A typical command might look like this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cat log_file &lt;span class="p"&gt;|&lt;/span&gt; grep &lt;span class="s2"&gt;&amp;#34;ERROR&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Or, more directly:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;grep &lt;span class="s2"&gt;&amp;#34;ERROR&amp;#34;&lt;/span&gt; log_file
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;However, instead of displaying the matching log entries, you may occasionally encounter the following message:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;grep: &lt;span class="o"&gt;(&lt;/span&gt;standard input&lt;span class="o"&gt;)&lt;/span&gt;: binary file matches
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The surprising part is that the &lt;code&gt;.log&lt;/code&gt; file appears to contain ordinary text, yet &lt;code&gt;grep&lt;/code&gt; treats it as a binary file and refuses to display the matching lines.&lt;/p&gt;
&lt;p&gt;This issue can occur when inspecting Laravel application logs, server logs, and other text-based log files.&lt;/p&gt;
&lt;p&gt;In this article, we&amp;rsquo;ll explore why this happens and walk through several practical ways to restore normal log searching.&lt;/p&gt;
&lt;h2 id="1-why-does-grep-report-binary-file-matches"&gt;1. Why Does grep Report &amp;ldquo;Binary File Matches&amp;rdquo;?
&lt;/h2&gt;&lt;p&gt;By default, GNU &lt;code&gt;grep&lt;/code&gt; attempts to determine whether its input contains binary data.&lt;/p&gt;
&lt;p&gt;When it detects certain non-text bytes, particularly null bytes (&lt;code&gt;\x00&lt;/code&gt;), it may classify the input as binary.&lt;/p&gt;
&lt;p&gt;To avoid printing potentially corrupted or unreadable content to the terminal, &lt;code&gt;grep&lt;/code&gt; suppresses matching lines and displays a message similar to:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;Binary file filename matches
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;When reading from a pipe, the message may look like this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;grep: &lt;span class="o"&gt;(&lt;/span&gt;standard input&lt;span class="o"&gt;)&lt;/span&gt;: binary file matches
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;There are several possible reasons why this happens.&lt;/p&gt;
&lt;h3 id="11-null-bytes-in-log-files"&gt;1.1 Null Bytes in Log Files
&lt;/h3&gt;&lt;p&gt;One common trigger is the presence of null bytes (&lt;code&gt;\x00&lt;/code&gt;) in the input.&lt;/p&gt;
&lt;p&gt;Although application logs are generally expected to contain plain text, unexpected binary data or file corruption can introduce null bytes into them.&lt;/p&gt;
&lt;p&gt;Possible causes include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Unexpected process termination during file operations.&lt;/li&gt;
&lt;li&gt;Application bugs that write binary data into log files.&lt;/li&gt;
&lt;li&gt;Incorrect handling of request payloads.&lt;/li&gt;
&lt;li&gt;File corruption or unexpected data introduced during log transfer.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;However, a null byte does not automatically mean that the disk is damaged. The actual source should be investigated before assuming filesystem corruption.&lt;/p&gt;
&lt;h3 id="12-binary-data-written-to-application-logs"&gt;1.2 Binary Data Written to Application Logs
&lt;/h3&gt;&lt;p&gt;Another possibility is that an application writes binary content directly into its logs.&lt;/p&gt;
&lt;p&gt;For example, a Laravel application might accidentally log:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Uploaded file contents.&lt;/li&gt;
&lt;li&gt;Raw binary request payloads.&lt;/li&gt;
&lt;li&gt;Encrypted or compressed data.&lt;/li&gt;
&lt;li&gt;Data that has not been properly encoded before logging.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This can happen when debugging code records entire request bodies or objects without checking their contents.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-php" data-lang="php"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nx"&gt;Log&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="na"&gt;debug&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;getContent&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If the request contains binary data, the resulting log entry may no longer be ordinary readable text.&lt;/p&gt;
&lt;h3 id="13-encoding-issues-or-corrupted-data"&gt;1.3 Encoding Issues or Corrupted Data
&lt;/h3&gt;&lt;p&gt;Logs may also contain invalid or unexpected character sequences due to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Incorrect character encoding.&lt;/li&gt;
&lt;li&gt;Data conversion problems.&lt;/li&gt;
&lt;li&gt;Corrupted log transfers.&lt;/li&gt;
&lt;li&gt;Application-level serialization issues.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It is worth noting that invalid UTF-8 alone does not necessarily trigger GNU &lt;code&gt;grep&lt;/code&gt;&amp;rsquo;s binary-file detection. The presence of null bytes or other binary indicators is often more relevant.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="2-how-to-fix-the-problem"&gt;2. How to Fix the Problem
&lt;/h2&gt;&lt;p&gt;You usually don&amp;rsquo;t need to modify or delete the original log file to continue troubleshooting.&lt;/p&gt;
&lt;p&gt;Here are three practical approaches.&lt;/p&gt;
&lt;h3 id="method-1-force-grep-to-treat-the-input-as-text-recommended"&gt;Method 1: Force grep to Treat the Input as Text (Recommended)
&lt;/h3&gt;&lt;p&gt;The simplest solution is to use the &lt;code&gt;-a&lt;/code&gt; option, which is equivalent to &lt;code&gt;--text&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This tells &lt;code&gt;grep&lt;/code&gt; to process the input as text, even if it contains bytes that would otherwise trigger binary-file detection.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Search a log file directly:&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;grep -a &lt;span class="s2"&gt;&amp;#34;ERROR&amp;#34;&lt;/span&gt; ./storage/logs/laravel-2026-11-04.log
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Or use it with a pipe:&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cat ./storage/logs/laravel-2026-11-04.log &lt;span class="p"&gt;|&lt;/span&gt; grep -a &lt;span class="s2"&gt;&amp;#34;ERROR&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The first approach is generally preferable because it avoids an unnecessary &lt;code&gt;cat&lt;/code&gt; process.&lt;/p&gt;
&lt;p&gt;You can also use &lt;code&gt;-i&lt;/code&gt; for case-insensitive searches:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;grep -ai &lt;span class="s2"&gt;&amp;#34;error&amp;#34;&lt;/span&gt; ./storage/logs/laravel-2026-11-04.log
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To display matching line numbers:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;grep -an &lt;span class="s2"&gt;&amp;#34;ERROR&amp;#34;&lt;/span&gt; ./storage/logs/laravel-2026-11-04.log
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Why this works:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;-a&lt;/code&gt; option disables binary-file suppression. &lt;code&gt;grep&lt;/code&gt; continues searching and prints matching lines instead of replacing the output with a binary-file warning.&lt;/p&gt;
&lt;p&gt;Keep in mind that if the matching lines contain binary bytes, the terminal output may still look unusual.&lt;/p&gt;
&lt;h3 id="method-2-remove-null-bytes-before-searching"&gt;Method 2: Remove Null Bytes Before Searching
&lt;/h3&gt;&lt;p&gt;If you&amp;rsquo;ve confirmed that null bytes are interfering with your log inspection, you can remove them from the input stream using &lt;code&gt;tr&lt;/code&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cat ./storage/logs/laravel-2026-11-04.log &lt;span class="p"&gt;|&lt;/span&gt; tr -d &lt;span class="s1"&gt;&amp;#39;\000&amp;#39;&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; grep &lt;span class="s2"&gt;&amp;#34;ERROR&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;A cleaner version avoids the unnecessary &lt;code&gt;cat&lt;/code&gt; command:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;tr -d &lt;span class="s1"&gt;&amp;#39;\000&amp;#39;&lt;/span&gt; &amp;lt; ./storage/logs/laravel-2026-11-04.log &lt;span class="p"&gt;|&lt;/span&gt; grep &lt;span class="s2"&gt;&amp;#34;ERROR&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;How it works:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;tr -d '\000'&lt;/code&gt; removes null bytes from the input.&lt;/li&gt;
&lt;li&gt;The resulting text is passed to &lt;code&gt;grep&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;grep&lt;/code&gt; searches the cleaned stream for matching entries.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This approach is useful when null bytes are the specific problem.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; This only changes the data being passed through the pipeline. It does not modify the original log file.&lt;/p&gt;
&lt;p&gt;Also, removing null bytes is not a universal solution for all binary content. If the log contains other binary data, additional investigation may be necessary.&lt;/p&gt;
&lt;h3 id="method-3-use-less-for-interactive-log-inspection"&gt;Method 3: Use less for Interactive Log Inspection
&lt;/h3&gt;&lt;p&gt;Sometimes you don&amp;rsquo;t need to extract matching lines immediately. You simply want to inspect a log file and navigate through its contents.&lt;/p&gt;
&lt;p&gt;In that case, &lt;code&gt;less&lt;/code&gt; is a convenient alternative:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;less ./storage/logs/laravel-2026-11-04.log
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Inside &lt;code&gt;less&lt;/code&gt;, you can use the following shortcuts:&lt;/p&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Shortcut&lt;/th&gt;
					&lt;th&gt;Description&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;/ERROR&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Search forward for ERROR&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;n&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Jump to the next match&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;N&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Jump to the previous match&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;G&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Go to the end of the file&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;g&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Go to the beginning&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;q&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Quit&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;For files containing binary data, you can also try:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;less -f ./storage/logs/laravel-2026-11-04.log
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The &lt;code&gt;-f&lt;/code&gt; option forces &lt;code&gt;less&lt;/code&gt; to open files even when they do not appear to be regular text files.&lt;/p&gt;
&lt;p&gt;However, binary content may still be displayed as unreadable characters.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="3-how-to-identify-the-actual-problem"&gt;3. How to Identify the Actual Problem
&lt;/h2&gt;&lt;p&gt;Although &lt;code&gt;grep -a&lt;/code&gt; is usually enough to restore log searching, recurring binary-file warnings deserve further investigation.&lt;/p&gt;
&lt;p&gt;Here are a few commands that can help.&lt;/p&gt;
&lt;h3 id="check-for-null-bytes"&gt;Check for Null Bytes
&lt;/h3&gt;&lt;p&gt;Use &lt;code&gt;grep&lt;/code&gt; to locate lines containing null bytes:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;grep -nUa &lt;span class="s1"&gt;$&amp;#39;\x00&amp;#39;&lt;/span&gt; ./storage/logs/laravel-2026-11-04.log
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Alternatively, inspect the file using &lt;code&gt;od&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;od -An -tx1 -N256 ./storage/logs/laravel-2026-11-04.log
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This displays the first 256 bytes in hexadecimal format, making unexpected &lt;code&gt;00&lt;/code&gt; bytes easier to identify.&lt;/p&gt;
&lt;h3 id="check-disk-space"&gt;Check Disk Space
&lt;/h3&gt;&lt;p&gt;If you suspect disk-related problems, check available filesystem space:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;df -h
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To inspect inode usage:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;df -i
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;A full disk can cause application logging and other file operations to fail. However, it does not necessarily mean that a full disk directly introduced null bytes into the log.&lt;/p&gt;
&lt;h3 id="check-application-logging-code"&gt;Check Application Logging Code
&lt;/h3&gt;&lt;p&gt;For Laravel applications, review any code that logs raw request bodies or uploaded file contents.&lt;/p&gt;
&lt;p&gt;Avoid blindly writing binary payloads into application logs.&lt;/p&gt;
&lt;p&gt;For example, instead of logging an entire request body:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-php" data-lang="php"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nx"&gt;Log&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="na"&gt;debug&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;getContent&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Consider logging useful metadata:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-php" data-lang="php"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nx"&gt;Log&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="na"&gt;debug&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Incoming request&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s1"&gt;&amp;#39;content_type&amp;#39;&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Content-Type&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s1"&gt;&amp;#39;content_length&amp;#39;&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;strlen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;getContent&lt;/span&gt;&lt;span class="p"&gt;()),&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This provides useful debugging information without unnecessarily dumping potentially sensitive or binary content into your logs.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="4-best-practices-for-searching-linux-logs"&gt;4. Best Practices for Searching Linux Logs
&lt;/h2&gt;&lt;p&gt;For everyday server troubleshooting, these commands cover most common scenarios.&lt;/p&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Task&lt;/th&gt;
					&lt;th&gt;Command&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;Search for errors&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;grep &amp;quot;ERROR&amp;quot; app.log&lt;/code&gt;&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Force text processing&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;grep -a &amp;quot;ERROR&amp;quot; app.log&lt;/code&gt;&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Case-insensitive search&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;grep -ai &amp;quot;error&amp;quot; app.log&lt;/code&gt;&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Show line numbers&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;grep -an &amp;quot;ERROR&amp;quot; app.log&lt;/code&gt;&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Remove null bytes&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;tr -d '\000' &amp;lt; app.log | grep &amp;quot;ERROR&amp;quot;&lt;/code&gt;&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Follow new log entries&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;tail -f app.log&lt;/code&gt;&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Search while following logs&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;tail -f app.log | grep --line-buffered &amp;quot;ERROR&amp;quot;&lt;/code&gt;&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;For Laravel applications, you can also monitor the latest log entries directly:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;tail -f storage/logs/laravel.log
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This is particularly useful when reproducing an application error and watching the corresponding log output in real time.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="5-conclusion"&gt;5. Conclusion
&lt;/h2&gt;&lt;p&gt;The &lt;code&gt;grep: binary file matches&lt;/code&gt; message does not necessarily mean your log file is completely corrupted.&lt;/p&gt;
&lt;p&gt;In many cases, &lt;code&gt;grep&lt;/code&gt; simply detects binary indicators in the input and suppresses normal text output.&lt;/p&gt;
&lt;p&gt;Here is the recommended approach:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Quick fix:&lt;/strong&gt; Use &lt;code&gt;grep -a&lt;/code&gt; to force text processing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Null-byte cleanup:&lt;/strong&gt; Use &lt;code&gt;tr -d '\000'&lt;/code&gt; when null bytes are confirmed to be the issue.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Interactive inspection:&lt;/strong&gt; Use &lt;code&gt;less&lt;/code&gt; to navigate through large log files.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Root-cause investigation:&lt;/strong&gt; Check for unexpected binary payloads, application logging mistakes, and potential file corruption.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For most day-to-day Linux troubleshooting tasks, &lt;code&gt;grep -a&lt;/code&gt; is the quickest and simplest solution.&lt;/p&gt;
&lt;p&gt;More importantly, if this happens repeatedly, investigate why binary data is entering your application logs rather than relying permanently on a workaround.&lt;/p&gt;</description></item></channel></rss>