<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Sujan Shrestha's Blog]]></title><description><![CDATA[Sujan Shrestha's Blog]]></description><link>https://blog.thesuzan.com</link><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Apr 2026 17:34:50 GMT</lastBuildDate><atom:link href="https://blog.thesuzan.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Thinking Outside the for Loop with List Comprehensions]]></title><description><![CDATA[Imagine writing a long for loop to create a list in Python, only to find that there is another simpler, more concise way to do the same thing. And that is exactly what List Comprehension in Python is.
The Python documentation defines it as:

List com...]]></description><link>https://blog.thesuzan.com/thinking-outside-the-for-loop-with-list-comprehensions</link><guid isPermaLink="true">https://blog.thesuzan.com/thinking-outside-the-for-loop-with-list-comprehensions</guid><category><![CDATA[Python 3]]></category><category><![CDATA[Python]]></category><category><![CDATA[python beginner]]></category><category><![CDATA[list comprehension]]></category><category><![CDATA[Programming Blogs]]></category><dc:creator><![CDATA[Sujan Shrestha]]></dc:creator><pubDate>Sat, 02 Aug 2025 06:12:18 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/W-ypTC6R7_k/upload/c511c6c4e307e0e0d29bdd43416fc6cc.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Imagine writing a long <code>for</code> loop to create a list in Python, only to find that there is another simpler, more concise way to do the same thing. And that is exactly what List Comprehension in Python is.</p>
<p>The Python <a target="_blank" href="https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions">documentation</a> defines it as:</p>
<blockquote>
<p>List comprehensions provide a concise way to create lists. Common applications are to make new lists where each element is the result of some operations applied to each member of another sequence or iterable, or to create a subsequence of those elements that satisfy a certain condition.</p>
</blockquote>
<p>The syntax for List Comprehension goes like this:</p>
<pre><code class="lang-python">[expression <span class="hljs-keyword">for</span> item <span class="hljs-keyword">in</span> iterable <span class="hljs-keyword">if</span> condition]
</code></pre>
<ul>
<li><p>expression: The operation or value applied to each item before it is added to the new list.</p>
</li>
<li><p>item: The current value being iterated over from the iterable.</p>
</li>
<li><p>iterable: An iterable, i.e. list, tuple, set, dictionary, range, etc.</p>
</li>
<li><p>if condition (optional): A <em>filtering</em> condition to determine if an element is to be included or not.</p>
</li>
</ul>
<p>With this syntax, the whole for loop block is condensed into a single line.</p>
<h2 id="heading-example">Example</h2>
<pre><code class="lang-python">even = []

<span class="hljs-keyword">for</span> n <span class="hljs-keyword">in</span> range(<span class="hljs-number">10</span>):
    <span class="hljs-keyword">if</span> n % <span class="hljs-number">2</span> == <span class="hljs-number">0</span>:
        even.append(n)
</code></pre>
<p>The code above creates a list of even numbers less than 10. The code spans 4 lines and has indentations. It is also necessary to initiate an empty list before we run the for loop to add the values to the list.</p>
<p>Now let’s look at the same functionality using a List Comprehension.</p>
<pre><code class="lang-python">even = [n <span class="hljs-keyword">for</span> n <span class="hljs-keyword">in</span> range(<span class="hljs-number">10</span>) <span class="hljs-keyword">if</span> n % <span class="hljs-number">2</span> == <span class="hljs-number">0</span>]
</code></pre>
<p>Amazing! This looks so much simpler. The list is initiated with the functionality, it only spans a single line, and it is much more concise. Here is the breakdown:</p>
<p>iterable: range(10)</p>
<p>item: n</p>
<p>if condition: n%2 == 0</p>
<p>expression: n (here, no transformation is done on the final value)</p>
<p>Now, we talked about expression in the syntax, and that it can be used to transform the final value before being added to the list. Let’s take a look at how we can do that.</p>
<p>For example, let’s create a list of the squares of all the even numbers from 0 to 9. We can do this by tweaking the expression part of the last code.</p>
<pre><code class="lang-python">squares_of_evens = [n * n <span class="hljs-keyword">for</span> n <span class="hljs-keyword">in</span> range(<span class="hljs-number">10</span>) <span class="hljs-keyword">if</span> n % <span class="hljs-number">2</span> == <span class="hljs-number">0</span>]
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Integration in Distributed Systems]]></title><description><![CDATA[In today's interconnected world, software systems rarely exist in isolation. Applications are increasingly built as distributed systems, spanning multiple machines and often vast geographical distances. This distributed nature brings significant adva...]]></description><link>https://blog.thesuzan.com/integration-in-distributed-systems</link><guid isPermaLink="true">https://blog.thesuzan.com/integration-in-distributed-systems</guid><category><![CDATA[distributed system]]></category><category><![CDATA[distributed systems]]></category><category><![CDATA[messaging]]></category><category><![CDATA[Messaging queue]]></category><category><![CDATA[RPC]]></category><category><![CDATA[gRPC]]></category><dc:creator><![CDATA[Sujan Shrestha]]></dc:creator><pubDate>Sun, 26 Jan 2025 04:08:07 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1737863914003/19fc849e-ff5b-40c2-8845-139b8a1d6c63.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In today's interconnected world, software systems rarely exist in isolation. Applications are increasingly built as distributed systems, spanning multiple machines and often vast geographical distances. This distributed nature brings significant advantages, like scalability, fault tolerance, and resource sharing. However, it also introduces a fundamental challenge: how do these independent components work together seamlessly? The answer lies in effective integration. This post explores the essential role of integration in distributed systems, examining various integration methods, their strengths and weaknesses, and how they address the complexities of building robust and scalable distributed applications. Understanding these techniques is crucial for anyone involved in designing, developing, or deploying modern software systems.</p>
<h2 id="heading-distributed-systems">Distributed systems</h2>
<p>A collection of multiple independent computer systems which work together to create, what appears to be a single, coherent system to the users of the system is called distributed systems. They coordinate their activities to achieve a common goal, but are not inherently dependent on each other for basic functioning.</p>
<h2 id="heading-why-integration-is-necessary-in-distributed-systems">Why integration is necessary in distributed systems</h2>
<p>Because of the distributed nature of distributed systems there needs to be some mechanism where the ambiguous parts of the systems needs to communicate. Integration methods provide a way for these systems to communicate with each other about the processs and trigger actions on the other parts to complete the overall process. To make the system whole, coordination between the ambiguous parts and data consistency is also required.</p>
<h2 id="heading-integration-styles">Integration Styles</h2>
<ol>
<li><p>File Transfer</p>
</li>
<li><p>Shared Database</p>
</li>
<li><p>Remote Procedure Invocation</p>
</li>
<li><p>Messaging</p>
</li>
</ol>
<h3 id="heading-file-transfer">File Transfer</h3>
<p>One part of the distributed system produces a file containing the shared data that is subsequently read by other applications. This approach is generally simple but there are things that need to be previously agreed upon.</p>
<ul>
<li><p>The format of the file and the layout. XML is becoming popular for this use.</p>
</li>
<li><p>Management of the file</p>
</li>
<li><p>Update propagation: When the file is updated by an application, other applications using the file to maintain their state needs to be notified of the change.</p>
</li>
</ul>
<h3 id="heading-shared-database">Shared Database</h3>
<p>Instead of sharing the file, the data is shared using a shared database. Usually a query language such as SQL will be used by all dependent applications to access the data. Modern databases also have the ability to have update alerts when any change occurs. Some drawbacks include: 1. having to design a database schema, which would be hard to determine if the future integrating applications are unknown in advance. 2. Frequent database transaction can easily cause a bottleneck. There is also a case of single point of failure if not designed carefully.</p>
<h3 id="heading-remote-procedure-call">Remote procedure call</h3>
<p>The methods discussed upto this point assumes that it is enough to trigger another application to act after the total completion of an action on another application. But it would be better to be able to trigger actions in applications after every action in a series of actions. This can be done through remote procedure calls</p>
<h3 id="heading-messaging">Messaging</h3>
<p>We cannot assume 100% availability of any application and it is mandatory for RPCs that the receiving side is available at the time the sender is sending a procedure call. Message queues solve that by making sure that the request is eventually delivered and the request is fulfilled.</p>
<p>Integration is the backbone of any successful distributed system. Choosing the right method depends on the specific needs of your application, balancing factors like performance, complexity, and security. While traditional methods like RPCs and shared databases still have their place, newer approaches like message queues and RESTful APIs offer compelling advantages in terms of scalability and flexibility. As distributed systems continue to evolve, understanding these core integration styles, their trade-offs, and emerging trends will be essential for building robust, scalable, and efficient applications that meet the demands of our increasingly interconnected world. This post provided a foundational overview; exploring each method in greater depth would be a worthwhile next step in your distributed systems journey.</p>
]]></content:encoded></item><item><title><![CDATA[The Power of $(): Your Guide to Command Substitution in Bash]]></title><description><![CDATA[Today, we're diving into a fundamental yet incredibly useful concept in the Linux shell (like Bash, which many use daily): command substitution using $().
If you've spent any time tinkering with the command line, you've likely encountered situations ...]]></description><link>https://blog.thesuzan.com/the-power-of-your-guide-to-command-substitution-in-bash</link><guid isPermaLink="true">https://blog.thesuzan.com/the-power-of-your-guide-to-command-substitution-in-bash</guid><category><![CDATA[Bash]]></category><category><![CDATA[shell scripting]]></category><category><![CDATA[Linux]]></category><category><![CDATA[command line]]></category><category><![CDATA[Command substitution]]></category><dc:creator><![CDATA[Sujan Shrestha]]></dc:creator><pubDate>Wed, 17 Jun 2020 06:15:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/udBkennKG90/upload/a70fd761ce2b09c24528dbc5ab843113.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Today, we're diving into a fundamental yet incredibly useful concept in the Linux shell (like Bash, which many use daily): <strong>command substitution using</strong> <code>$()</code>.</p>
<p>If you've spent any time tinkering with the command line, you've likely encountered situations where you need the <em>output</em> of one command to be used as an <em>argument</em> or part of another command. That's precisely where <code>$()</code> comes into play.</p>
<p><strong>What is Command Substitution?</strong></p>
<p>At its core, command substitution allows you to execute a command and seamlessly inject its standard output directly into your current command line. Think of it as a way to dynamically generate parts of your commands based on the results of other commands.</p>
<p><strong>The</strong> <code>$()</code> Syntax: Clean and Powerful</p>
<p>The preferred and more modern way to perform command substitution in Bash is by enclosing the command you want to execute within parentheses preceded by a dollar sign:</p>
<pre><code class="lang-bash">$(your_command_here)
</code></pre>
<p>When the shell encounters this structure, it does the following:</p>
<ol>
<li><p><strong>Executes</strong> <code>your_command_here</code>.</p>
</li>
<li><p><strong>Captures the standard output</strong> produced by that command.</p>
</li>
<li><p><strong>Replaces the entire</strong> <code>$(your_command_here)</code> expression with the captured output.</p>
</li>
</ol>
<p><strong>Let's See It in Action: Practical Examples</strong></p>
<p>Here are a few real-world scenarios where <code>$()</code> shines:</p>
<p><strong>1. Getting the Current Date and Time:</strong></p>
<p>Want to include the current timestamp in a message or filename? <code>$()</code> makes it a breeze:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> <span class="hljs-string">"The current date and time is: <span class="hljs-subst">$(date)</span>"</span>
</code></pre>
<p><strong>2. Storing a User's Name in a Variable:</strong></p>
<p>Need to programmatically access the currently logged-in user?</p>
<pre><code class="lang-bash">loggedInUser=$(whoami)
<span class="hljs-built_in">echo</span> <span class="hljs-string">"Welcome, <span class="hljs-variable">$loggedInUser</span>!"</span>
</code></pre>
<p><strong>3. Using the Path of an Executable:</strong></p>
<p>Imagine you want to see detailed information about a specific command, like <code>python3</code>:</p>
<pre><code class="lang-bash">ls -l $(<span class="hljs-built_in">which</span> python3)
</code></pre>
<p>Here, <code>which python3</code> finds the full path to the Python 3 executable, and that path is then passed as an argument to <code>ls -l</code>.</p>
<p><strong>4. Counting Files in a Directory:</strong></p>
<p>For more complex operations, you can even nest commands within <code>$()</code>:</p>
<pre><code class="lang-bash">fileCount=$(ls -p | grep -v / | wc -l)
<span class="hljs-built_in">echo</span> <span class="hljs-string">"There are <span class="hljs-variable">$fileCount</span> files in the current directory."</span>
</code></pre>
<p>This snippet first lists all entries with a trailing <code>/</code> for directories, then filters out those directories, and finally counts the remaining lines (which are files).</p>
<p><strong>Why</strong> <code>$()</code> is Better Than Backticks (``)</p>
<p>While the older backtick syntax achieves the same goal, <code>$()</code> offers significant advantages:</p>
<ul>
<li><p><strong>Easier Nesting:</strong> When you need to embed command substitutions within other command substitutions, <code>$()</code> handles it much more cleanly without the need for cumbersome escaping.</p>
<pre><code class="lang-bash">  <span class="hljs-comment"># With backticks (harder to read):</span>
  nestedResult=`<span class="hljs-built_in">echo</span> <span class="hljs-string">"The user is \`whoami\`"</span>`

  <span class="hljs-comment"># With $(), much clearer:</span>
  nestedResult=$(<span class="hljs-built_in">echo</span> <span class="hljs-string">"The user is <span class="hljs-subst">$(whoami)</span>"</span>)
</code></pre>
</li>
<li><p><strong>Improved Readability:</strong> The <code>$()</code> syntax is generally considered more intuitive and easier to parse, especially for complex commands. It visually separates the command being executed.</p>
</li>
</ul>
<p><strong>Embrace the Power of</strong> <code>$()</code></p>
<p>As you continue your journey with the Linux command line, mastering tools like command substitution is crucial. The <code>$()</code> syntax provides a clean, powerful, and readable way to leverage the output of commands, making your shell interactions and scripting much more efficient and flexible.</p>
<p>So, the next time you need to weave the result of one command into another, remember the power of <code>$()</code> – your trusty tool for dynamic command construction in the Linux shell!</p>
<p>What are some ways you've used command substitution in your own Linux adventures? Share your experiences in the comments below!</p>
]]></content:encoded></item><item><title><![CDATA[Mastering grep: Your Essential Linux Text Searching Tool]]></title><description><![CDATA[grep is a powerful command-line utility in Linux and other Unix-like operating systems used for searching plain-text data sets for lines matching a regular expression. Its name comes from the ed command g/re/p (globally search a regular expression an...]]></description><link>https://blog.thesuzan.com/mastering-grep-your-essential-linux-text-searching-tool</link><guid isPermaLink="true">https://blog.thesuzan.com/mastering-grep-your-essential-linux-text-searching-tool</guid><category><![CDATA[grep]]></category><category><![CDATA[Linux]]></category><category><![CDATA[command line]]></category><category><![CDATA[terminal]]></category><category><![CDATA[Regular Expressions]]></category><category><![CDATA[Regex]]></category><dc:creator><![CDATA[Sujan Shrestha]]></dc:creator><pubDate>Wed, 10 Jun 2020 06:15:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/IuMKwupOsc0/upload/df11bac156f653002d434a00b9b25ba0.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><code>grep</code> is a powerful command-line utility in Linux and other Unix-like operating systems used for <strong>searching plain-text data sets for lines matching a regular expression</strong>. Its name comes from the ed command <code>g/re/p</code> (globally search a regular expression and print matching lines).</p>
<p>Here's a comprehensive guide on how to use <code>grep</code>:</p>
<p><strong>Basic Syntax:</strong></p>
<pre><code class="lang-bash">grep [OPTIONS] PATTERN [FILE...]
</code></pre>
<ul>
<li><p><code>OPTIONS</code>: Flags that modify the behavior of <code>grep</code>.</p>
</li>
<li><p><code>PATTERN</code>: The regular expression you want to search for. It can be a simple string or a complex pattern.</p>
</li>
<li><p><code>FILE...</code>: The name(s) of the file(s) to search within. If no file is specified, <code>grep</code> reads from standard input (stdin), which can be the output of another command piped to <code>grep</code>.</p>
</li>
</ul>
<p><strong>Commonly Used Options:</strong></p>
<ul>
<li><p><code>-i</code>, <code>--ignore-case</code>: Ignore case distinctions in both the pattern and the input files.</p>
<pre><code class="lang-bash">  grep -i <span class="hljs-string">"hello"</span> myfile.txt  <span class="hljs-comment"># Matches "hello", "Hello", "HELLO", etc.</span>
</code></pre>
</li>
<li><p><code>-v</code>, <code>--invert-match</code>: Select non-matching lines. Print only the lines that do <em>not</em> contain the pattern.</p>
<pre><code class="lang-bash">  grep -v <span class="hljs-string">"error"</span> logfile.txt <span class="hljs-comment"># Shows lines that don't contain "error".</span>
</code></pre>
</li>
<li><p><code>-n</code>, <code>--line-number</code>: Prefix each matching line with its line number in the input file.</p>
<pre><code class="lang-bash">  grep -n <span class="hljs-string">"keyword"</span> document.txt
</code></pre>
</li>
<li><p><code>-c</code>, <code>--count</code>: Suppress normal output; instead, print a count of matching lines for each input file.</p>
<pre><code class="lang-bash">  grep -c <span class="hljs-string">"word"</span> anotherfile.txt <span class="hljs-comment"># Shows how many lines contain "word".</span>
</code></pre>
</li>
<li><p><code>-r</code>, <code>--recursive</code>: Recursively search directories. If files are specified, <code>grep</code> will search all files under each directory specified.</p>
<pre><code class="lang-bash">  grep -r <span class="hljs-string">"config"</span> /etc/  <span class="hljs-comment"># Searches for "config" in all files under /etc/.</span>
</code></pre>
</li>
<li><p><code>-l</code>, <code>--files-with-matches</code>: Suppress normal output; instead, print only the names of files containing matches.</p>
<pre><code class="lang-bash">  grep -l <span class="hljs-string">"function"</span> *.c    <span class="hljs-comment"># Lists C files containing "function".</span>
</code></pre>
</li>
<li><p><code>-w</code>, <code>--word-regexp</code>: Select only those lines containing matches that form whole words. The pattern must be surrounded by non-word characters (or the beginning/end of a line).</p>
<pre><code class="lang-bash">  grep -w <span class="hljs-string">"the"</span> text.txt  <span class="hljs-comment"># Matches "the" but not "there" or "other".</span>
</code></pre>
</li>
<li><p><code>-o</code>, <code>--only-matching</code>: Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line.</p>
<pre><code class="lang-bash">  <span class="hljs-built_in">echo</span> <span class="hljs-string">"This line has one two three words."</span> | grep -o <span class="hljs-string">"\w+"</span> <span class="hljs-comment"># Prints each word on a new line.</span>
</code></pre>
</li>
<li><p><code>-E</code>, <code>--extended-regexp</code>: Interpret PATTERN as an extended regular expression (ERE). This allows for more powerful and flexible pattern matching (e.g., using <code>+</code>, <code>?</code>, <code>|</code>, <code>()</code>).</p>
<pre><code class="lang-bash">  grep -E <span class="hljs-string">"cat|dog"</span> pets.txt <span class="hljs-comment"># Matches lines containing "cat" or "dog".</span>
</code></pre>
</li>
<li><p><code>-F</code>, <code>--fixed-strings</code>: Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched. This is useful when you're searching for exact strings and don't need regular expression features.</p>
<pre><code class="lang-bash">  grep -F <span class="hljs-string">"apple\nbanana"</span> fruits.txt <span class="hljs-comment"># Matches lines containing "apple" or "banana".</span>
</code></pre>
</li>
<li><p><code>-A NUM</code>, <code>--after-context=NUM</code>: Print NUM lines of trailing context after matching lines.</p>
<pre><code class="lang-bash">  grep -A 2 <span class="hljs-string">"warning"</span> log.txt <span class="hljs-comment"># Shows the "warning" line and the 2 lines after it.</span>
</code></pre>
</li>
<li><p><code>-B NUM</code>, <code>--before-context=NUM</code>: Print NUM lines of leading context before matching lines.</p>
<pre><code class="lang-bash">  grep -B 1 <span class="hljs-string">"error"</span> log.txt   <span class="hljs-comment"># Shows the line before "error" and the "error" line.</span>
</code></pre>
</li>
<li><p><code>-C NUM</code>, <code>--context=NUM</code>: Print NUM lines of output context.</p>
<pre><code class="lang-bash">  grep -C 1 <span class="hljs-string">"info"</span> log.txt    <span class="hljs-comment"># Shows the line before, the "info" line, and the line after.</span>
</code></pre>
</li>
</ul>
<p><strong>Basic Examples:</strong></p>
<ol>
<li><p><strong>Search for a string in a file:</strong></p>
<pre><code class="lang-bash"> grep <span class="hljs-string">"search term"</span> myfile.txt
</code></pre>
</li>
<li><p><strong>Search for a case-insensitive string:</strong></p>
<pre><code class="lang-bash"> grep -i <span class="hljs-string">"CASE"</span> data.log
</code></pre>
</li>
<li><p><strong>Find lines that do NOT contain a string:</strong></p>
<pre><code class="lang-bash"> grep -v <span class="hljs-string">"exclude"</span> results.txt
</code></pre>
</li>
<li><p><strong>Count the number of lines containing a string:</strong></p>
<pre><code class="lang-bash"> grep -c <span class="hljs-string">"important"</span> report.txt
</code></pre>
</li>
<li><p><strong>Find all occurrences of a word in files ending with</strong> <code>.txt</code>:</p>
<pre><code class="lang-bash"> grep -w <span class="hljs-string">"keyword"</span> *.txt
</code></pre>
</li>
<li><p><strong>Search recursively for a string in a directory:</strong></p>
<pre><code class="lang-bash"> grep -r <span class="hljs-string">"find this"</span> /home/user/documents
</code></pre>
</li>
<li><p><strong>Pipe the output of another command to</strong> <code>grep</code>:</p>
<pre><code class="lang-bash"> ls -l | grep <span class="hljs-string">"^-"</span>      <span class="hljs-comment"># List only files (lines starting with '-')</span>
 ps aux | grep <span class="hljs-string">"firefox"</span> <span class="hljs-comment"># Find processes related to Firefox</span>
</code></pre>
</li>
</ol>
<p><strong>Regular Expressions with</strong> <code>grep</code>:</p>
<p><code>grep</code>'s power comes from its ability to use regular expressions for pattern matching. Here are some basic regex metacharacters:</p>
<ul>
<li><p><code>.</code> : Matches any single character (except newline).</p>
</li>
<li><p><code>*</code> : Matches the preceding element zero or more times.</p>
</li>
<li><p><code>+</code> : Matches the preceding element one or more times (with <code>-E</code>).</p>
</li>
<li><p><code>?</code> : Matches the preceding element zero or one time (with <code>-E</code>).</p>
</li>
<li><p><code>^</code> : Matches the beginning of a line.</p>
</li>
<li><p><code>$</code> : Matches the end of a line.</p>
</li>
<li><p><code>[ ]</code> : Matches any single character within the brackets (e.g., <code>[aeiou]</code> matches any vowel).</p>
</li>
<li><p><code>[^ ]</code> : Matches any single character NOT within the brackets (e.g., <code>[^0-9]</code> matches any non-digit).</p>
</li>
<li><p><code>()</code> : Groups elements together (with <code>-E</code>).</p>
</li>
<li><p><code>|</code> : Matches either the expression before or the expression after the pipe (with <code>-E</code>).</p>
</li>
<li><p><code>\</code> : Escapes a special character to treat it literally (e.g., <code>\.</code> matches a literal dot).</p>
</li>
<li><p><code>\w</code> : Matches any word character (alphanumeric and underscore).</p>
</li>
<li><p><code>\d</code> : Matches any digit.</p>
</li>
<li><p><code>\s</code> : Matches any whitespace character.</p>
</li>
</ul>
<p><strong>Examples using Regular Expressions:</strong></p>
<pre><code class="lang-bash">grep <span class="hljs-string">"^start"</span> file.txt       <span class="hljs-comment"># Lines starting with "start"</span>
grep <span class="hljs-string">"end$"</span> file.txt         <span class="hljs-comment"># Lines ending with "end"</span>
grep <span class="hljs-string">"a.b"</span> file.txt          <span class="hljs-comment"># Lines containing "a" followed by any char, then "b"</span>
grep <span class="hljs-string">"a*b"</span> file.txt          <span class="hljs-comment"># Lines containing "a" zero or more times, then "b"</span>
grep <span class="hljs-string">"[0-9]"</span> file.txt        <span class="hljs-comment"># Lines containing at least one digit</span>
grep <span class="hljs-string">"[^a-z]"</span> file.txt       <span class="hljs-comment"># Lines containing at least one non-lowercase letter</span>
grep -E <span class="hljs-string">"cat|dog"</span> pets.txt   <span class="hljs-comment"># Lines containing "cat" or "dog"</span>
grep -E <span class="hljs-string">"(ab)+"</span> data.txt     <span class="hljs-comment"># Lines containing one or more occurrences of "ab"</span>
</code></pre>
<p><strong>Choosing Between</strong> <code>grep</code>, <code>egrep</code>, and <code>fgrep</code>:</p>
<ul>
<li><p><code>grep</code>: Basic regular expression syntax is the default.</p>
</li>
<li><p><code>egrep</code> (equivalent to <code>grep -E</code>): Uses extended regular expression syntax, offering more powerful pattern matching.</p>
</li>
<li><p><code>fgrep</code> (equivalent to <code>grep -F</code>): Treats the pattern as a fixed string, not a regular expression. It's faster for simple string searches.</p>
</li>
</ul>
<p>In modern systems, <code>grep -E</code> is often preferred for complex patterns, while <code>grep</code> is sufficient for basic string matching. <code>fgrep</code> is useful when you need to search for literal strings containing special regex characters.</p>
<p>By understanding these options and the basics of regular expressions, you can effectively use <code>grep</code> to find and filter information within text data. Remember to consult the <code>man grep</code> page for a complete list of options and more advanced usage.</p>
]]></content:encoded></item><item><title><![CDATA[Linux Man]]></title><description><![CDATA[Alright, let's learn how to read a man page! "Man" stands for "manual," and man pages are the standard form of documentation for commands, system calls, libraries, and more on Unix-like operating systems like Linux and macOS.
Here's a step-by-step gu...]]></description><link>https://blog.thesuzan.com/linux-man</link><guid isPermaLink="true">https://blog.thesuzan.com/linux-man</guid><category><![CDATA[Linux]]></category><category><![CDATA[unix]]></category><category><![CDATA[macOS]]></category><category><![CDATA[man pages]]></category><category><![CDATA[command line]]></category><category><![CDATA[terminal]]></category><category><![CDATA[documentation]]></category><category><![CDATA[Tutorial]]></category><category><![CDATA[guide]]></category><category><![CDATA[cli]]></category><dc:creator><![CDATA[Sujan Shrestha]]></dc:creator><pubDate>Tue, 02 Jun 2020 18:15:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/xbEVM6oJ1Fs/upload/badd734bd80d5bbe860052af26f5149f.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Alright, let's learn how to read a man page! "Man" stands for "manual," and man pages are the standard form of documentation for commands, system calls, libraries, and more on Unix-like operating systems like Linux and macOS.</p>
<p>Here's a step-by-step guide:</p>
<p><strong>1. Accessing a Man Page:</strong></p>
<p>To view the man page for a specific command, function, or file, you use the <code>man</code> command followed by its name.</p>
<pre><code class="lang-bash">man ls      <span class="hljs-comment"># View the man page for the 'ls' command</span>
man <span class="hljs-built_in">printf</span>  <span class="hljs-comment"># View the man page for the 'printf' command</span>
man open    <span class="hljs-comment"># View the man page for the 'open' system call</span>
man 3 <span class="hljs-built_in">printf</span> <span class="hljs-comment"># View the man page for the 'printf' library function (section 3)</span>
man 5 passwd <span class="hljs-comment"># View the man page for the 'passwd' file format (section 5)</span>
</code></pre>
<p><strong>2. Understanding the Structure:</strong></p>
<p>When you open a man page, it's typically structured into several sections. The most common ones are:</p>
<ul>
<li><p><strong>NAME:</strong> A brief one-line description of the command or topic.</p>
</li>
<li><p><strong>SYNOPSIS:</strong> Shows the command's syntax, including options and arguments. Optional parts are usually enclosed in square brackets <code>[]</code>, and alternatives are often separated by pipes <code>|</code>.</p>
</li>
<li><p><strong>DESCRIPTION:</strong> A detailed explanation of what the command or topic does, its options, and how to use it.</p>
</li>
<li><p><strong>OPTIONS:</strong> A list of command-line options with their descriptions.</p>
</li>
<li><p><strong>FILES:</strong> Lists any files that the command uses or affects.</p>
</li>
<li><p><strong>EXAMPLES:</strong> Provides practical examples of how to use the command.</p>
</li>
<li><p><strong>SEE ALSO:</strong> Lists related man pages that you might find helpful.</p>
</li>
<li><p><strong>AUTHOR:</strong> The author(s) of the command or documentation.</p>
</li>
<li><p><strong>REPORTING BUGS:</strong> Instructions on how to report any bugs you find.</p>
</li>
<li><p><strong>COPYRIGHT:</strong> Information about the software's license.</p>
</li>
</ul>
<p><strong>3. Navigating the Man Page:</strong></p>
<p>Once the man page is open, you can use the following keys to navigate:</p>
<ul>
<li><p><strong>Spacebar:</strong> Scroll down one screen.</p>
</li>
<li><p><code>b</code>: Scroll up one screen.</p>
</li>
<li><p><strong>Down arrow (</strong><code>↓</code>) or <code>j</code>: Scroll down one line.</p>
</li>
<li><p><strong>Up arrow (</strong><code>↑</code>) or <code>k</code>: Scroll up one line.</p>
</li>
<li><p><code>g</code>: Go to the beginning of the man page.</p>
</li>
<li><p><code>G</code>: Go to the end of the man page.</p>
</li>
<li><p><code>/pattern</code>: Search forward for the <code>pattern</code>. Press <code>n</code> to go to the next match and <code>N</code> to go to the previous match.</p>
</li>
<li><p><code>?pattern</code>: Search backward for the <code>pattern</code>. Press <code>n</code> to go to the next match and <code>N</code> to go to the previous match.</p>
</li>
<li><p><code>q</code>: Quit the man page viewer.</p>
</li>
<li><p><code>h</code>: Display help information within the man page viewer.</p>
</li>
</ul>
<p><strong>4. Understanding Sections:</strong></p>
<p>Man pages are organized into numbered sections to help you find the right information. Here are some common sections:</p>
<ul>
<li><p><strong>1: Executable programs or shell commands:</strong> These are the commands you typically run in the terminal (e.g., <code>ls</code>, <code>grep</code>, <code>sed</code>).</p>
</li>
<li><p><strong>2: System calls (functions provided by the kernel):</strong> These describe the interface to the operating system kernel (e.g., <code>read</code>, <code>write</code>, <code>open</code>).</p>
</li>
<li><p><strong>3: Library calls (functions within program libraries):</strong> These describe functions available in programming libraries (e.g., <code>printf</code>, <code>malloc</code>). You often need to specify the section number when looking up library functions to avoid conflicts with commands of the same name.</p>
</li>
<li><p><strong>4: Special files (usually devices found in</strong> <code>/dev</code>): These describe device files and their usage (e.g., <code>null</code>, <code>tty</code>).</p>
</li>
<li><p><strong>5: File formats and conventions:</strong> These describe the structure and syntax of configuration files (e.g., <code>passwd</code>, <code>hosts</code>).</p>
</li>
<li><p><strong>6: Games:</strong> Documentation for games.</p>
</li>
<li><p><strong>7: Miscellaneous (macro packages and conventions):</strong> This section covers various topics, including man page standards and conventions.</p>
</li>
<li><p><strong>8: System administration commands (usually only for root):</strong> These are commands typically used by system administrators (e.g., <code>useradd</code>, <code>ifconfig</code>).</p>
</li>
</ul>
<p>When you use <code>man &lt;name&gt;</code>, it usually defaults to showing the man page in the lowest-numbered section that exists for that name. If you want a specific section, you can specify it like <code>man &lt;section_number&gt; &lt;name&gt;</code>.</p>
<p><strong>5. Reading and Interpreting:</strong></p>
<ul>
<li><p><strong>Start with the NAME and SYNOPSIS:</strong> This gives you a quick overview of the command and its basic usage. Pay attention to the options and arguments.</p>
</li>
<li><p><strong>Read the DESCRIPTION carefully:</strong> This section provides the details you need to understand how the command works and what its options do.</p>
</li>
<li><p><strong>Look at the OPTIONS:</strong> Each option will be explained, including its short form (e.g., <code>-l</code>) and long form (e.g., <code>--list</code>). Understand what each option modifies.</p>
</li>
<li><p><strong>Check the EXAMPLES:</strong> The examples are often the most helpful part for understanding practical usage. Try running similar commands yourself.</p>
</li>
<li><p><strong>Use SEE ALSO:</strong> If you're looking for related commands or more information, follow the links in the "SEE ALSO" section.</p>
</li>
</ul>
<p><strong>Example Walkthrough:</strong> <code>man ls</code></p>
<ol>
<li><p><code>man ls</code>: Opens the man page for the <code>ls</code> command.</p>
</li>
<li><p><strong>NAME:</strong> You'll see something like: <code>ls - list directory contents</code>. This tells you the basic purpose of <code>ls</code>.</p>
</li>
<li><p><strong>SYNOPSIS:</strong> You'll see the general syntax, like: <code>ls [OPTION]... [FILE]...</code>. This indicates that <code>ls</code> can take zero or more options and zero or more file or directory arguments. The square brackets <code>[]</code> mean these are optional.</p>
</li>
<li><p><strong>DESCRIPTION:</strong> This section will explain in detail what <code>ls</code> does (lists files and directories), how it sorts the output by default, and the general behavior.</p>
</li>
<li><p><strong>OPTIONS:</strong> This is a long list explaining each available option, such as <code>-l</code> (long listing), <code>-a</code> (show all files, including hidden ones), <code>-h</code> (human-readable sizes), <code>-r</code> (reverse order), and many more. Read the description for each option you're interested in.</p>
</li>
<li><p><strong>EXAMPLES:</strong> This section will show you how to use <code>ls</code> with different combinations of options to achieve specific results. For example:</p>
<pre><code class="lang-bash"> ls -l
 ls -a /home/user
 ls --sort=size -h
</code></pre>
</li>
<li><p><strong>SEE ALSO:</strong> You might see references to other related commands like <code>dir</code>, <code>vdir</code>, and <code>find</code>.</p>
</li>
</ol>
<p><strong>Tips for Effective Man Page Reading:</strong></p>
<ul>
<li><p><strong>Be patient:</strong> Man pages can sometimes be dense, but they contain a wealth of information.</p>
</li>
<li><p><strong>Focus on what you need:</strong> You don't always need to read the entire man page. Look for the sections relevant to your current task.</p>
</li>
<li><p><strong>Experiment:</strong> Try out the commands and options you learn about in the man page in a safe environment (e.g., a test directory).</p>
</li>
<li><p><strong>Use the search function:</strong> If you're looking for a specific keyword or option, use <code>/</code> to search.</p>
</li>
<li><p><strong>Don't be afraid to look up terms you don't understand:</strong> You might encounter technical terms. Use <code>man man</code> to learn more about man pages themselves or use online search engines for other terms.</p>
</li>
</ul>
<p>By following these steps and practicing, you'll become proficient at reading and understanding man pages, which is an essential skill for anyone working with Linux or other Unix-like systems. Good luck!</p>
]]></content:encoded></item></channel></rss>