<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Grep on Cheat Sheet</title><link>/tags/grep/</link><description>Recent content in Grep on Cheat Sheet</description><generator>Hugo</generator><language>en</language><lastBuildDate>Sun, 24 May 2026 00:00:00 +0000</lastBuildDate><atom:link href="/tags/grep/index.xml" rel="self" type="application/rss+xml"/><item><title>grep</title><link>/linux/cli/grep/</link><pubDate>Sun, 24 May 2026 00:00:00 +0000</pubDate><guid>/linux/cli/grep/</guid><description>&lt;h1 id="grep"&gt;&lt;code&gt;grep&lt;/code&gt;&lt;a class="anchor" href="#grep"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;h3 id="general-usage"&gt;General Usage&lt;a class="anchor" href="#general-usage"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;grep &amp;lt;options&amp;gt; &amp;lt;pattern&amp;gt; &amp;lt;file&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="common-flags"&gt;Common Flags&lt;a class="anchor" href="#common-flags"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-i, --ignore-case&lt;/code&gt;&lt;/strong&gt;: Ignore case distinctions.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-v, --invert-match&lt;/code&gt;&lt;/strong&gt;: Invert the sense of matching, selecting non-matching lines.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-l, --files-with-matches&lt;/code&gt;&lt;/strong&gt;: Print only the names of files with matching lines.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-q, --quiet, --silent&lt;/code&gt;&lt;/strong&gt;: Do not write anything to standard output. Exit immediately with zero status if any match is found.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-n, --line-number&lt;/code&gt;&lt;/strong&gt;: Prefix each line of output with its 1-based line number.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-E, --extended-regexp&lt;/code&gt;&lt;/strong&gt;: Interpret patterns as extended regular expressions (ERE).
&lt;ul&gt;
&lt;li&gt;eg. &lt;code&gt;grep -E '&amp;lt;pattern1&amp;gt;|&amp;lt;pattern2&amp;gt;|...' &amp;lt;file&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-r, --recursive&lt;/code&gt;&lt;/strong&gt;: Read all files under each directory, recursively.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-A &amp;lt;num&amp;gt;, --after-context=&amp;lt;num&amp;gt;&lt;/code&gt;&lt;/strong&gt;: Print &lt;code&gt;&amp;lt;num&amp;gt;&lt;/code&gt; lines of trailing context after matching lines.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-B &amp;lt;num&amp;gt;, --before-context=&amp;lt;num&amp;gt;&lt;/code&gt;&lt;/strong&gt;: Print &lt;code&gt;&amp;lt;num&amp;gt;&lt;/code&gt; lines of leading context before matching lines.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-C &amp;lt;num&amp;gt;, --context=&amp;lt;num&amp;gt;&lt;/code&gt;&lt;/strong&gt;: Print &lt;code&gt;&amp;lt;num&amp;gt;&lt;/code&gt; lines of output context.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="posix-character-classes"&gt;POSIX Character Classes&lt;a class="anchor" href="#posix-character-classes"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Used within bracket expressions &lt;code&gt;[ ]&lt;/code&gt;.&lt;/p&gt;</description></item></channel></rss>