<?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" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Tanishka Makode - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Tanishka Makode - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Sun, 24 May 2026 22:24:01 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/author/tanishkamakode/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ Learn User Management in RHEL: A Comprehensive Guide ]]>
                </title>
                <description>
                    <![CDATA[ Imagine you're throwing a house party. You wouldn’t hand out keys to every guest, right? Some friends can roam freely, some should probably stick to the living room, and a few—well, let’s just say they need supervision. Managing users in RHEL is kind... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/learn-user-management-in-rhel-a-comprehensive-guide/</link>
                <guid isPermaLink="false">67b5da0a6db178277c2bebc9</guid>
                
                    <category>
                        <![CDATA[ Linux ]]>
                    </category>
                
                    <category>
                        <![CDATA[ RHEL ]]>
                    </category>
                
                    <category>
                        <![CDATA[ user management ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Tanishka Makode ]]>
                </dc:creator>
                <pubDate>Wed, 19 Feb 2025 13:18:02 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1739971027992/d19c4616-4c2e-4cc4-ac45-384e6520d1a8.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Imagine you're throwing a house party. You wouldn’t hand out keys to every guest, right? Some friends can roam freely, some should probably stick to the living room, and a few—well, let’s just say they need supervision.</p>
<p>Managing users in RHEL is kind of like that. You decide who gets in, what they can do, and how much control they have. Without proper management, things can get messy fast—like that friend who somehow DJs when no one asks.</p>
<p>So, let’s dive into user management and ensure your Linux system stays organized, secure, and drama-free! 🚀</p>
<h2 id="heading-table-of-contents">Table Of Contents</h2>
<ol>
<li><p><a class="post-section-overview" href="#heading-what-is-a-user-in-linux">What is a User in Linux?</a></p>
<ul>
<li><a class="post-section-overview" href="#heading-understanding-sudo-in-user-management">Understanding sudo in User Management</a></li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-user-management-commands-in-linux">User Management Commands in Linux</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-how-to-add-a-user">How to Add a User</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-check-if-a-user-is-created">How to Check if a User is Created</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-assign-a-password">How to Assign a Password</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-switch-users">How to Switch Users</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-understanding-groups-in-linux">Understanding Groups in Linux</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-modify-users">How to Modify Users</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-final-words">Final Words</a></p>
</li>
</ol>
<h2 id="heading-what-is-a-user-in-linux"><strong>What is a User in Linux?</strong></h2>
<p>A user in Linux is an account that allows someone (or a process) to interact with the system. Since Linux is a multi-user operating system, multiple users can exist on the same system, each with their own settings, files, and permissions. Users can have different levels of permissions, which determine what they can access or modify on the system.</p>
<p>Linux categorizes users into three main types based on their roles and privileges:</p>
<ol>
<li><p>Privileged Users: These users have unrestricted access to the entire system. They have the highest level of permissions and can perform any operation on the system. They can install/remove software, modify system files, create/manage users, and even delete everything. These users are also called root users.</p>
</li>
<li><p>System Users: The system creates these users to run background processes or services. They can’t login like a normal user. Their sole purpose is to manage system operations like databases, web servers and scheduled tasks.</p>
</li>
<li><p>Normal Users: These are the everyday users created by administrators or during system installation. They have their home directory and can store personal files and settings. They can’t modify system files but can execute tasks within their permission scope.</p>
</li>
</ol>
<h3 id="heading-understanding-sudo-in-user-management">Understanding <code>sudo</code> in User Management</h3>
<p>The <code>sudo</code> (Superuser Do) command allows a regular user to execute administrative tasks with elevated privileges. Since user management tasks—such as adding, modifying, or deleting users—require root access, normal users must use <code>sudo</code> before these commands.</p>
<p>Note that the following commands are executed as the root user. If you are using a normal user account, you must prefix them with <code>sudo</code> to perform user management tasks.</p>
<p>Now let’s see how we manage users on RHEL.</p>
<h2 id="heading-user-management-commands-in-linux">User Management Commands in Linux</h2>
<h3 id="heading-how-to-add-a-user">How to add a user</h3>
<p>To create a new user account, use following command:</p>
<p>Syntax:</p>
<pre><code class="lang-bash">useradd [user_name]
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash">useradd Tanishka <span class="hljs-comment"># Root user</span>
sudo useradd Tanishka <span class="hljs-comment"># Normal user</span>
</code></pre>
<p>Once you create a user, you can verify its existence in the <code>/etc/passwd</code> file. This file stores essential user account information (but <strong>not passwords</strong>, despite the name).</p>
<h4 id="heading-how-to-check-if-a-user-is-created">How to check if a user is created</h4>
<p>To confirm the user entry in <code>/etc/passwd</code>, use one of the following methods:</p>
<ol>
<li>View the file using <code>cat</code> or <code>grep</code></li>
</ol>
<pre><code class="lang-bash">cat /etc/passwd <span class="hljs-comment"># Displays entire file content</span>
grep Tanishka /etc/passwd <span class="hljs-comment"># Displays information about Tanishka user only</span>
</code></pre>
<ol start="2">
<li>Use id command:</li>
</ol>
<p>The <code>id</code> command is used to display a user’s <strong>UID (User ID), GID (Group ID), and the groups they belong to</strong>. It helps in verifying user information and checking permissions.</p>
<pre><code class="lang-bash">id Tanishka
<span class="hljs-comment"># Displays user id of Tanishka,</span>
<span class="hljs-comment"># hence verifying user has been created</span>
</code></pre>
<p>Let’s understand what’s going on in the /etc/password fields. Each line in <code>/etc/passwd</code> represents a user account and contains seven fields separated by colons (<code>:</code>):</p>
<pre><code class="lang-bash">username:x:UID:GID:comment:home_directory:shell
</code></pre>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Field</strong></td><td><strong>Description</strong></td></tr>
</thead>
<tbody>
<tr>
<td>username</td><td>Name of the user (for example, john, admin).</td></tr>
<tr>
<td>x</td><td>Placeholder for the password (actual password is stored in /etc/shadow).</td></tr>
<tr>
<td>UID</td><td>User ID (for example, 1001 for a normal user, 0 for root).</td></tr>
<tr>
<td>GID</td><td>Group ID (primary group of the user).</td></tr>
<tr>
<td>comment</td><td>Optional user description (for example, full name or other info).</td></tr>
<tr>
<td>home_directory</td><td>User’s home directory (for example /home/john).</td></tr>
<tr>
<td>shell</td><td>The default shell assigned to the user (for example, /bin/bash, /bin/sh, /usr/sbin/nologin).</td></tr>
</tbody>
</table>
</div><h3 id="heading-how-to-assign-a-password">How to Assign a Password</h3>
<p>Once an account is created, it’s essential to assign a password to the account. Otherwise, that account can’t be logged in through a GUI login interface. To give a password to a user account, user this command:</p>
<p>Syntax:</p>
<pre><code class="lang-bash">passwd [user_name]
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash">passwd Tanishka
</code></pre>
<p>You will be prompted to enter the password. Enter the password and you’re all set! Even though user information is stored in /etc/passwd file, actual information about the password is stored in the /etc/shadow file (weird, I know…).</p>
<p>To see the content of the /etc/shadow file, use this command:</p>
<pre><code class="lang-bash">cat /etc/shadow
</code></pre>
<p>Each line in <code>/etc/shadow</code> represents a user account password and contains nine fields separated by colons (<code>:</code>):</p>
<pre><code class="lang-bash">username:password:lastchg:min:max:warn:inactive:expire:reserved
</code></pre>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Field</td><td>Description</td></tr>
</thead>
<tbody>
<tr>
<td>username</td><td>User’s login name</td></tr>
<tr>
<td>password</td><td>Encrypted password or password status (for example, locked)</td></tr>
<tr>
<td>lastchg</td><td>Last password change (days since Jan 1, 1970)</td></tr>
<tr>
<td>min</td><td>Minimum days between password changes</td></tr>
<tr>
<td>max</td><td>Maximum days before password change is required</td></tr>
<tr>
<td>warn</td><td>Warning period before password expiration</td></tr>
<tr>
<td>inactive</td><td>Inactive period after password expiration</td></tr>
<tr>
<td>expire</td><td>Account expiration date (days since Jan 1, 1970)</td></tr>
<tr>
<td>reserved</td><td>Reserved for future use</td></tr>
</tbody>
</table>
</div><p>To change password aging information, you use the <code>chage</code> (short for change age) command like this:</p>
<p>Syntax:</p>
<pre><code class="lang-bash">chage [OPTIONS] [user_name]
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash">chage -l tanishka <span class="hljs-comment"># Lists the current password aging information</span>
chage -m 10 tanishka <span class="hljs-comment"># Sets the minimum days to change password</span>
chage -M 10 tanishka <span class="hljs-comment"># Sets the maximum days password must be changed</span>
chage -W 7 tanishka <span class="hljs-comment"># Sets the number of days before the password expires that the user will be warned to change the password</span>
chage -I 10 tanishka <span class="hljs-comment"># Sets the number of days after password expiration that the account will be disabled if not logged in</span>
chage -E 2025-12-31 tanishka <span class="hljs-comment"># Sets the date when the user account will expire </span>
chage -d 2024-12-25 tanishka <span class="hljs-comment"># Sets the last password change date</span>
</code></pre>
<p>Now that you have learned to create users and assign passwords, you need to know how to switch between users. Let’s see that now.</p>
<h3 id="heading-how-to-switch-users">How to Switch Users</h3>
<p>The <code>su</code> (Substitute User) command allows you to <strong>switch from one user to another</strong> without logging out of the current session.</p>
<p>Syntax:</p>
<pre><code class="lang-bash">su - [user_name]
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash">su - Tanishka <span class="hljs-comment"># Switches to Tanishka user</span>
</code></pre>
<ul>
<li><p><code>su</code> stands for "substitute user" (or "switch user").</p>
</li>
<li><p>The <code>-</code> (hyphen) loads the target user's full environment, including their shell, path, and profile settings (similar to logging in as that user).</p>
</li>
<li><p>If no username is provided, it switches to the root user by default.</p>
</li>
</ul>
<p>To return to original or root user, simply enter ‘exit’.</p>
<h3 id="heading-understanding-groups-in-linux">Understanding Groups in Linux</h3>
<p>Just like a party where guests can belong to different social circles, Linux groups allow users to be part of different permission levels. Groups help manage file access, system privileges, and administrative controls efficiently.</p>
<p>Linux has two types of groups:</p>
<p><strong>1. Primary Group:</strong></p>
<ul>
<li><p>Every user has one primary group.</p>
</li>
<li><p>When a user creates a new file, it belongs to their primary group.</p>
</li>
<li><p>It is usually named the same as the username.</p>
</li>
</ul>
<p><strong>2. Secondary Groups:</strong></p>
<ul>
<li><p>A user can belong to multiple secondary groups.</p>
</li>
<li><p>These groups provide additional permissions beyond the primary group.</p>
</li>
<li><p>Users can be assigned to various secondary groups to access shared resources.</p>
</li>
</ul>
<p>To check a user’s group membership:</p>
<pre><code class="lang-bash">id [user_name]
</code></pre>
<p>This displays the user’s UID, primary group (GID), and any secondary groups they belong to.</p>
<p>To add a new group:</p>
<pre><code class="lang-bash">groupadd [group_name]
</code></pre>
<h3 id="heading-how-to-modify-a-user">How to Modify a User</h3>
<p>Sometimes, you might need to update user details, such as changing usernames, user IDs, group memberships, home directories, or login shells. You use the <code>usermod</code> command to modify existing user accounts while preserving their files and configurations.</p>
<p>Syntax:</p>
<pre><code class="lang-bash">usermod [OPTIONS] [user_name]
</code></pre>
<p>Let’s break down the different options available for modifying user accounts.</p>
<ol>
<li><strong>Change the username</strong></li>
</ol>
<p>If you want to rename an existing user, use the <code>-l</code> option:</p>
<p>Syntax:</p>
<pre><code class="lang-bash">usermod -l new_username old_username
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash">usermod -l tanishkamakode tanishka
</code></pre>
<p>This renames <code>tanishka</code> to <code>tanishkamakode</code>. Just keep in mind that the home directory remains the same (<code>/home/tanishka</code>), so you might need to rename it manually.</p>
<p>To rename the home directory as well, use:</p>
<pre><code class="lang-bash">mv /home/tanishka /home/tanishkamakode
</code></pre>
<ol start="2">
<li><strong>Change the user id:</strong></li>
</ol>
<p>Each user has a unique User ID (UID). If you need to change it, use <code>-u</code>.</p>
<p>Syntax:</p>
<pre><code class="lang-bash">usermod -u new_UID user_name
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash">usermod -u 2001 tanishka
</code></pre>
<p>This changes <code>tanishka</code>'s UID to <code>2001</code>. Before you do this, you’ll want to <strong>make sure that no other user has the same UID.</strong> This is important.</p>
<p>If the user owns files under the old UID, you should update them after changing the UID.</p>
<ol start="3">
<li><strong>Change the primary group</strong></li>
</ol>
<p>Every user belongs to a primary group. To change it, use <code>-g</code>.</p>
<p>Syntax:</p>
<pre><code class="lang-bash">usermod -g new_group user_name
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash">usermod -g developers tanishka
</code></pre>
<p>This changes <code>tanishka</code>'s primary group to <code>developers</code>. Just keep in mind that <code>usermod -g developers tanishka</code> <strong>removes</strong> the user from all secondary groups. To avoid that, just make sure you check and re-add secondary groups as needed.</p>
<p>Also, the group must exist beforehand. To create a group, run this command:</p>
<p>Syntax:</p>
<pre><code class="lang-bash">groupadd [group_name]
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash">groupadd developers
</code></pre>
<p>Now, to check tanishka’s group, do the following:</p>
<pre><code class="lang-bash">id tanishka
</code></pre>
<ol start="4">
<li><strong>Add to a secondary group</strong></li>
</ol>
<p>A user can belong to multiple secondary groups. Use <code>-G</code> to assign them.</p>
<p>Syntax:</p>
<pre><code class="lang-bash">usermod -G group1,group2 user_name
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash">usermod -G linux,docker tanishka
</code></pre>
<p>This adds <code>tanishka</code> to the <code>sudo</code> and <code>docker</code> groups. Just keep in mind that this <strong>replaces</strong> any existing secondary groups that the user might already belong to. To add groups without removing the current ones, use <code>-aG</code> (append to groups) like this:</p>
<pre><code class="lang-bash">usermod -aG linux,docker tanishka
</code></pre>
<ol start="5">
<li><strong>Change the home directory:</strong></li>
</ol>
<p>You can change a user’s default home directory using <code>-d</code>.</p>
<p>Syntax:</p>
<pre><code class="lang-bash">usermod -d /new/home_directory user_name
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash">usermod -d /home/tani tanishka
</code></pre>
<p>This sets <code>tanishka</code>'s home directory to <code>/home/tani</code>, but <strong>it does not move existing files</strong>. To move them, add the <code>-m</code> option:</p>
<pre><code class="lang-bash">usermod -d /home/tani -m tanishka
</code></pre>
<p>After moving the home directory, just make sure you’ve updated file ownership.</p>
<ol start="6">
<li><strong>Change the login shell:</strong></li>
</ol>
<p>The default shell for a user can be changed using <code>-s</code>.</p>
<p>Syntax:</p>
<pre><code class="lang-bash">usermod -s /new/shell user_name
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash">usermod -s /bin/zsh tanishka
</code></pre>
<p>This changes <code>tanishka</code>'s default shell to <code>zsh</code>. Common shells include:</p>
<ul>
<li><p><code>/bin/bash</code> (default)</p>
</li>
<li><p><code>/bin/sh</code></p>
</li>
<li><p><code>/bin/zsh</code></p>
</li>
<li><p><code>/usr/sbin/nologin</code> (to disable login)</p>
</li>
</ul>
<p>With <code>usermod</code>, you can fine-tune user settings to match system requirements. Always check changes using:</p>
<pre><code class="lang-bash">id tanishka
grep tanishka /etc/passwd
</code></pre>
<h2 id="heading-final-words">Final Words</h2>
<p>In this article, we explored the fundamentals of user management in RHEL, a crucial aspect of system administration. We started with creating and managing users, then moved on to handling groups.</p>
<p>If you're new to Linux and want to build a strong foundation, check out my first tutorial on <a target="_blank" href="https://www.freecodecamp.org/news/guide-to-rhel-linux-basics/">Basic Linux Commands</a>, where I cover essential commands every beginner should know. You can also read my second tutorial on <a target="_blank" href="https://www.freecodecamp.org/news/how-to-use-the-vim-text-editor-intro-for-devs/">Vim</a> to learn how to navigate and edit text efficiently in this powerful editor. These articles will complement what you’ve learned about user management here.</p>
<p>Keep practicing these commands, and soon they’ll become second nature to you. Mastery comes with repetition, so continue experimenting and applying these fundamentals in real-world scenarios.</p>
<p>Stay tuned for more articles. Get ready to take your RHEL skills to the next level.</p>
<p><a target="_blank" href="https://linktr.ee/tanishkamakode">Let’s connect!</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use the Vim Text Editor – An Introduction for Developers ]]>
                </title>
                <description>
                    <![CDATA[ Imagine a carpenter without tools, a writer without a pen, or a chef without a knife—this is like trying to imagine a developer or sysadmin without a reliable text editor. For devs, text editors are the ultimate multitools, shaping how we create, man... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-use-the-vim-text-editor-intro-for-devs/</link>
                <guid isPermaLink="false">67a24bb37e501febb084c852</guid>
                
                    <category>
                        <![CDATA[ vim ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Linux ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Text Editors ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Tanishka Makode ]]>
                </dc:creator>
                <pubDate>Tue, 04 Feb 2025 17:17:39 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1738684583892/739ec0fa-e8a2-4f08-a265-7fa5034c932d.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Imagine a carpenter without tools, a writer without a pen, or a chef without a knife—this is like trying to imagine a developer or sysadmin without a reliable text editor.</p>
<p>For devs, text editors are the ultimate multitools, shaping how we create, manage, and transform raw data into meaningful output.</p>
<p>While modern editors like VS Code and Sublime Text have gained popularity for their sleek interfaces, there’s something timeless about the simplicity and power of classic tools.</p>
<p>Loved by some and feared by others, Vim is a text editor that has stood the test of time. Born from its predecessor Vi, Vim (Vi Improved) offers unparalleled speed, versatility, and control.</p>
<p>In this tutorial, you’ll learn what makes Vim so special. We’ll explore its commands, text filtering, and string manipulation capabilities to help you harness its true power.</p>
<h2 id="heading-what-well-cover">What we’ll cover:</h2>
<ol>
<li><p><a class="post-section-overview" href="#heading-text-editors-in-linux">Text Editors in Linux</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-open-the-vim-editor">How to Open the Vim Editor</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-modes-in-vim">Modes in Vim</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-basic-vim-commands">Basic Vim Commands</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-cut-copy-paste-and-delete-commands">Cut, Copy, Paste, and Delete Commands</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-search-and-replace-commands">Search and Replace Commands</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-read-files-using-more-and-less">How to Read Files using more and less</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-text-filters">Text Filters</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-text-summarization-tools-wc">Text Summarization Tool: wc</a></p>
</li>
</ol>
<h2 id="heading-text-editors-in-linux">Text Editors in Linux</h2>
<p>Linux provides a variety of text editors, each designed for different types of users – from beginners to advanced developers.</p>
<p>Editors like <strong>Nano</strong> are great for newcomers who need a simple, user-friendly experience in the terminal. Nano displays helpful commands at the bottom of the screen, making it easy to navigate without a steep learning curve.</p>
<p><strong>Gedit</strong>, the default editor for the GNOME desktop environment, offers a clean, graphical interface ideal for basic text editing. On the other hand, <strong>Kate</strong> caters to KDE desktop users and provides a more feature-rich experience, with multiple windows, syntax highlighting, and an integrated terminal.</p>
<p><strong>Emacs</strong> is a versatile and highly customizable editor that can be turned into an entire development environment, ideal for power users who want more than just a text editor.</p>
<p><strong>VS Code</strong> and <strong>Atom</strong> are modern, graphical editors that offer a rich set of features, including extensions, debugging tools, and Git integration, making them favorites among developers.</p>
<h3 id="heading-why-do-many-devs-prefer-vim">Why Do Many Devs Prefer Vim?</h3>
<p>Despite the wide range of text editors available in Linux, Vim stands out as the preferred choice for many users, especially those who need a lightweight, fast, and highly efficient editing environment.</p>
<p>Vim, an improved version of the classic Vi editor, is available on nearly every Linux distribution and can be used in both graphical and terminal-based environments. Its popularity stems from its exceptional speed and efficiency.</p>
<p>Vim is entirely keyboard-driven, allowing you to perform complex editing tasks quickly without the need for a mouse. This makes it incredibly useful for remote work, where you may have to rely on minimal system resources.</p>
<p>The power of Vim lies in its <strong>modal editing</strong> system, which separates the text input and command modes, which you’ll learn soon. This lets you execute precise actions with a few keystrokes. Whether you're navigating a file, searching for a string, or performing complex text manipulations, Vim enables you to do it all without taking your hands off the keyboard.</p>
<p>Because Vim (or Vi) is pre-installed on most Linux systems, it’s often the go-to option for developers and system administrators, who rely on its ubiquity and powerful features. In short, Vim’s combination of speed, versatility, and efficiency makes it the editor of choice for many Linux users looking to boost their productivity.</p>
<h2 id="heading-how-to-open-the-vim-editor">How to Open the Vim Editor</h2>
<p>Opening a file in Vim is straightforward and efficient. To start editing any file, simply use the following command in your terminal:</p>
<pre><code class="lang-bash">vim [filename]
</code></pre>
<p>Here, replace <code>[filename]</code> with the name of the file you want to open. If the file doesn't exist, Vim will create a new file with that name. Once executed, Vim will open the file and allow you to start editing right away.</p>
<p>Example:</p>
<pre><code class="lang-bash">vim data.txt <span class="hljs-comment"># A file that doesn't exist yet, so Vim creates a new file named data.txt</span>
</code></pre>
<p>When you execute the command <code>vim data.txt</code>, Vim opened a new file named <code>data.txt</code> because a file with this name did not previously exist in the current directory. In Vim, this is indicated by the message at the bottom of the editor, which reads: <code>data.txt [NEW]</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1736790675984/98007e6c-cc90-42be-b853-f239f4f2e819.png" alt="Creating a new file using vim command" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>If the file you want to edit already exists, you can open it in Vim by using the same command. You’ll be able to see its contents and make edits as needed. If you don’t see the <code>[New]</code> message at the bottom (as shown for new files), it confirms the file already exists.</p>
<h2 id="heading-modes-in-vim">Modes in Vim</h2>
<p>Vim has several modes, but the most commonly used ones are:</p>
<ul>
<li><p><strong>Normal Mode (Command Mode)</strong> – Used for navigation and executing commands.</p>
</li>
<li><p><strong>Insert Mode</strong> – Used for typing and editing text.</p>
</li>
</ul>
<p>When you open a file in Vim, it starts in Command Mode by default. This mode allows you to navigate, execute commands, and perform various operations without directly modifying the text. To edit the text in the file, you need to switch to Insert Mode.</p>
<h3 id="heading-what-is-command-mode"><strong>What is Command Mode?</strong></h3>
<p>Command Mode is the default mode in Vim. In this mode, you can navigate through the file using the arrow keys and cut, copy, paste, or delete the content and execute commands like saving or quitting.</p>
<p>To switch to Command Mode from any other mode, press the <code>Esc</code> key.</p>
<p>Example: If you are in Insert Mode and need to return to Command Mode to save or navigate, press <code>Esc</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1736791773096/298ef4f6-6fba-493d-b05c-0564290862a1.png" alt="Vim in command mode" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>In the above image, "hello.txt" 1L, 1B” indicates that the file <code>hello.txt</code> is open and is currently in Command Mode, which is the default mode when you open Vim. 1L Represents 1 line in the file (currently the file is empty, so there’s just one blank line). 1B Represents 1 byte (the file is currently empty)</p>
<h3 id="heading-what-is-insert-mode"><strong>What is Insert Mode?</strong></h3>
<p>Insert Mode allows you to edit or type text in the file, similar to a traditional text editor. You can insert new lines, modify existing text, and make changes directly.</p>
<p>Press <code>i</code> while in Command Mode. This switches to Insert Mode and places the cursor at the current position, allowing you to start typing.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1736791793215/93d1ff39-9015-4209-8903-e29d1ccfb7c1.png" alt="Editor switched to INSERT mode" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>In the above image, “—INSERT—” indicates that the editor has been switched to Insert Mode, allowing you to type and edit text directly in the file.</p>
<p>Quick glance: When you open a file, always check the bottom of the terminal to determine your current mode. If the bottom line displays file-related information, you are in Command Mode. If the bottom line explicitly says <code>-- INSERT --</code>, you are in Insert Mode. If you want to go from <strong>Command Mode to Insert Mode:</strong> Press <code>i</code>. And from <strong>Insert Mode to Command Mode:</strong> Press <code>Esc</code>.</p>
<h2 id="heading-basic-vim-commands">Basic Vim Commands</h2>
<p>Below are some essential commands to help you manage files efficiently in Vim.</p>
<p><strong>Note:</strong> Before using these commands, ensure you're in command mode by pressing <code>Esc</code>.</p>
<h3 id="heading-1-save-changes"><strong>1. Save Changes</strong></h3>
<p>To save the changes made to a file, use the following command:</p>
<pre><code class="lang-bash">:w
</code></pre>
<p>This writes (saves) the current file without exiting Vim.</p>
<h3 id="heading-2-save-changes-and-quit"><strong>2. Save Changes and Quit</strong></h3>
<p>If you're done editing and want to save changes and exit Vim simultaneously, use:</p>
<pre><code class="lang-bash">:wq
</code></pre>
<p>This command writes the changes and then quits the editor.</p>
<h3 id="heading-3-quit-without-saving-changes"><strong>3. Quit Without Saving Changes</strong></h3>
<p>If you wish to exit without saving any changes, you can use:</p>
<pre><code class="lang-bash">:q
</code></pre>
<p>This command will close the file if no changes have been made since the last save.</p>
<h3 id="heading-4-force-quit-without-saving-changes"><strong>4. Force Quit Without Saving Changes</strong></h3>
<p>In case you've made changes to the file but want to exit without saving them, you can force quit with:</p>
<pre><code class="lang-bash">:q!
</code></pre>
<p>The <code>!</code> overrides any unsaved changes and closes the file immediately.</p>
<h2 id="heading-cut-copy-paste-and-delete-commands-plus-others"><strong>Cut, Copy, Paste, and Delete Commands (Plus Others)</strong></h2>
<h3 id="heading-how-to-position-the-cursor-for-text-manipulation"><strong>How to Position the Cursor for Text Manipulation</strong></h3>
<p>Before using any of the commands listed below (copy, cut, paste, and delete), it's important to understand where to place the cursor.</p>
<ul>
<li><p><strong>Copy (Yank), Cut, Delete:</strong> For most operations, the cursor needs to be placed <strong>at the starting point of the text</strong> you want to act upon. This means if you're copying or cutting a word, place the cursor at the <strong>beginning</strong> of the word. If you're working with a line, the cursor should be anywhere on that line. For paragraph-based operations, position the cursor anywhere within the paragraph.</p>
</li>
<li><p><strong>Paste:</strong> The text will be pasted at the cursor's <strong>current position</strong>. So, ensure your cursor is placed where you want the copied or cut content to appear.</p>
</li>
</ul>
<p>For example, Let’s say I have a file.txt that has the following content -</p>
<pre><code class="lang-bash"><span class="hljs-comment"># file.txt</span>
Hey readers,  
In this blog, we<span class="hljs-string">'re learning Vim. This file is for demonstration purposes,
where we'</span>ll explore various editing commands like cut, copy, paste, and delete. Let<span class="hljs-string">'s dive in!  

Vim is a powerful text editor that comes pre-installed on most Unix-based systems.
Mastering Vim can significantly boost your efficiency as a developer.  

To start with, let'</span>s learn some basic navigation and text manipulation commands.
Stay tuned as we <span class="hljs-built_in">break</span> down each <span class="hljs-built_in">command</span> with examples!
</code></pre>
<p>All the commands mentioned below will use this file as reference to explain examples.</p>
<h3 id="heading-1-copy-yank"><strong>1. Copy (Yank)</strong></h3>
<p>In Vim, copying is called "yanking." Use the following commands to copy text. The cursor's position is important to ensure the correct text is copied.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Command</td><td>Description</td><td>Example</td></tr>
</thead>
<tbody>
<tr>
<td><code>yl</code></td><td>Copies a letter from the current cursor position (cursor must be on the left of the letter you want to copy)</td><td>If your cursor is on the left of <strong>"H"</strong> in <code>Hey readers,</code> and you type <code>yl</code>, Vim will copy <strong>"H"</strong> (only one character).</td></tr>
<tr>
<td><code>yw</code></td><td>Copies a word (cursor must be at the beginning of the word)</td><td>If your cursor is on the left of <strong>"blog,"</strong> in the sentence, Typing <code>yw</code> will copy <strong>"blog,"</strong> (including the comma).</td></tr>
<tr>
<td><code>yy</code></td><td>Copies the entire line (cursor can be anywhere on the line)</td><td>If your cursor is at any position on line 1 <strong>Hey readers,</strong> Typing <code>yy</code> will copy the entire line</td></tr>
<tr>
<td><code>2yy</code></td><td>Copies two lines, including the current cursor line (cursor can be anywhere on the first line)</td><td>If your cursor is at any position on line 1 <strong>Hey readers,</strong> Typing <code>2yy</code> will copy the entire line along with the next line.</td></tr>
<tr>
<td><code>y{</code></td><td>Copies the rest of the paragraph above the line where the cursor currently is (and including that line)</td><td>If your cursor is anywhere inside this paragraph 2 (Vim is a powerful text editor…), Typing <code>y{</code> will copy everything from the start of this paragraph up to the cursor position.</td></tr>
<tr>
<td><code>y}</code></td><td>Copies the rest of the paragraph below the line where the cursor currently is (and including that line)</td><td>If your cursor is anywhere inside this paragraph 2 (Vim is a powerful text editor…), Typing <code>y}</code> will copy everything from the current cursor position down to the end of the paragraph.</td></tr>
<tr>
<td><code>yG</code></td><td>Copies everything from the current line to the end of the file (cursor must be at the line where you want the copy operation to start)</td><td>If your cursor is at the beginning of this line “<strong>Vim is a powerful text editor…”,</strong> typing yG will copy this line and everything below it until the end of the file</td></tr>
</tbody>
</table>
</div><h3 id="heading-2-cut-change"><strong>2. Cut (Change)</strong></h3>
<p>Cutting in Vim is known as "changing" the text. The cut operation replaces the text. Just like with copying, the cursor's position is important when using cut commands.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Command</td><td>Description</td><td>Example</td></tr>
</thead>
<tbody>
<tr>
<td><code>cl</code></td><td>Cuts a letter from the current cursor position (cursor must be on the left of the letter you want to cut)</td><td>If your cursor is on the <strong>"H"</strong> in <code>"Hey readers,"</code> and you type <code>cl</code>, Vim will delete <strong>"H"</strong> and switch to insert mode, allowing you to type a replacement.</td></tr>
<tr>
<td><code>cw</code></td><td>Cuts a word (cursor must be at the beginning of the word)</td><td>If your cursor is on the <strong>"blog,"</strong> in the sentence, typing <code>cw</code> will delete <strong>"blog,"</strong> (including the comma) and switch to insert mode, allowing you to type a replacement.</td></tr>
<tr>
<td><code>caw</code></td><td>Cuts a word along with trailing whitespace (cursor must be at the beginning of the word)</td><td>If your cursor is anywhere inside <strong>"blog,"</strong>, typing <code>caw</code> will delete <strong>" blog,"</strong> (including the preceding space) and switch to insert mode.</td></tr>
<tr>
<td><code>cc</code></td><td>Cuts the entire line (cursor can be anywhere on the line)</td><td>If your cursor is at any position on line 1 (<code>Hey readers,</code>), typing <code>cc</code> will delete the whole line and switch to insert mode.</td></tr>
<tr>
<td><code>2cc</code></td><td>Cuts two lines, including the current cursor line (cursor can be anywhere on the first line)</td><td>If your cursor is at any position on line 1 (<code>Hey readers,</code>), typing <code>2cc</code> will delete this line along with the next line and switch to insert mode.</td></tr>
<tr>
<td><code>c{</code></td><td>Cuts the text in the paragraph above the cursor’s location</td><td>If your cursor is anywhere inside paragraph 2 (<code>Vim is a powerful text editor…</code>), typing <code>c{</code> will delete everything from the cursor position to the start of the paragraph and switch to insert mode.</td></tr>
<tr>
<td><code>c}</code></td><td>Cuts the text in the paragraphs below the cursor’s location</td><td>If your cursor is anywhere inside paragraph 2 (<code>Vim is a powerful text editor…</code>), typing <code>c}</code> will delete everything from the cursor position to the end of the paragraph and switch to insert mode.</td></tr>
<tr>
<td><code>cG</code></td><td>Cuts everything from the current line to the end of the file (cursor must be at the line where you want the cut operation to start)</td><td>If your cursor is at the beginning of this line (<code>Vim is a powerful text editor…</code>), typing <code>cG</code> will delete this line and everything below it until the end of the file, then switch to insert mode.</td></tr>
</tbody>
</table>
</div><h3 id="heading-3-paste"><strong>3. Paste</strong></h3>
<p>To paste the copied or cut text, use the following commands. The pasted text will appear at the <strong>current cursor position</strong>.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Command</td><td>Description</td></tr>
</thead>
<tbody>
<tr>
<td><code>p</code> (Lowercase)</td><td>Pastes the copied or cut text <strong>after</strong> the cursor</td></tr>
<tr>
<td><code>P</code> (Uppercase)</td><td>Pastes the copied or cut text <strong>before</strong> the cursor</td></tr>
</tbody>
</table>
</div><h3 id="heading-4-delete"><strong>4. Delete</strong></h3>
<p>Deleting text in Vim allows you to remove unwanted text while remaining in command mode. The cursor must be positioned correctly to delete the intended text. Once deleted, you can still paste the deleted text to a new location.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Command</td><td>Description</td><td>Example</td></tr>
</thead>
<tbody>
<tr>
<td><code>dl</code></td><td>Deletes a letter from the current cursor position (cursor must be on the left of the letter you want to delete)</td><td>If your cursor is on <strong>"H"</strong> in <code>"Hey readers,"</code> and you type <code>dl</code>, Vim will delete <strong>"H"</strong>.</td></tr>
<tr>
<td><code>dw</code></td><td>Deletes a word (cursor must be at the beginning of the word)</td><td>If your cursor is on <strong>"blog,"</strong> in the sentence, typing <code>dw</code> will delete <strong>"blog,"</strong> (including the comma).</td></tr>
<tr>
<td><code>daw</code></td><td>Deletes a word along with trailing whitespace (cursor must be at the beginning of the word)</td><td>If your cursor is anywhere inside <strong>"blog,"</strong>, typing <code>daw</code> will delete <strong>" blog,"</strong> (including the preceding space).</td></tr>
<tr>
<td><code>dd</code></td><td>Deletes the entire line (cursor can be anywhere on the line)</td><td>If your cursor is at any position on line 1 (<code>Hey readers,</code>), typing <code>dd</code> will delete the whole line.</td></tr>
<tr>
<td><code>2dd</code></td><td>Deletes two lines, including the current cursor line (cursor can be anywhere on the first line)</td><td>If your cursor is at any position on line 1 (<code>Hey readers,</code>), typing <code>2dd</code> will delete this line along with the next line.</td></tr>
<tr>
<td><code>d{</code></td><td>Deletes the paragraph above the cursor (cursor can be anywhere in the paragraph you want to delete)</td><td>If your cursor is anywhere inside paragraph 2 (<code>Vim is a powerful text editor…</code>), typing <code>d{</code> will delete everything from the cursor position to the start of the paragraph.</td></tr>
<tr>
<td><code>d}</code></td><td>Deletes the paragraph below the cursor (cursor can be anywhere in the paragraph you want to delete)</td><td>If your cursor is anywhere inside paragraph 2 (<code>Vim is a powerful text editor…</code>), typing <code>d}</code> will delete everything from the cursor position to the end of the paragraph.</td></tr>
<tr>
<td><code>dG</code></td><td>Deletes everything from the current line to the end of the file (cursor must be at the line where you want the delete operation to start)</td><td>If your cursor is at the beginning of this line (<code>Vim is a powerful text editor…</code>), typing <code>dG</code> will delete this line and everything below it until the end of the file.</td></tr>
</tbody>
</table>
</div><h3 id="heading-5-other-useful-commands"><strong>5. Other Useful Commands</strong></h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Commands</td><td>Description</td></tr>
</thead>
<tbody>
<tr>
<td><code>gg</code></td><td>Moves the cursor to the first line of the file</td></tr>
<tr>
<td><code>G</code></td><td>Moves the cursor to the last line of the file</td></tr>
<tr>
<td><code>:se nu</code></td><td>Sets line numbers in the file</td></tr>
<tr>
<td><code>:se nonu</code></td><td>Removes line numbers from the file</td></tr>
<tr>
<td><code>:u</code></td><td>Undoes the last action</td></tr>
<tr>
<td><code>:10</code></td><td>Jumps to line 10 (for example)</td></tr>
</tbody>
</table>
</div><p>Note that <strong>Delete</strong> removes text but doesn’t store it in the system clipboard by default. The text goes into Vim’s unnamed register, meaning it can be pasted within Vim but not outside it. <strong>Cut</strong> explicitly stores text in the clipboard so you can paste it outside Vim as well.</p>
<h2 id="heading-search-and-replace-commands"><strong>Search and Replace Commands</strong></h2>
<p>Vim provides powerful search and replace functionality that allows you to find specific words or patterns and replace them efficiently. Understanding how to search and replace text is key to improving your productivity when editing large files.</p>
<p>Below is a breakdown of the various search and replace commands in Vim.</p>
<h3 id="heading-search-commands"><strong>Search Commands</strong></h3>
<ul>
<li><p><strong>Search Forward</strong> (<code>/</code>): When you want to search for a word or pattern below the cursor, use the <code>/</code> command. This will search forward in the file.</p>
</li>
<li><p><strong>Search Backward</strong> (<code>?</code>): Similarly, if you want to search for a word or pattern above the cursor, use the <code>?</code> command. This will search backward in the file.</p>
</li>
</ul>
<p>After performing a search, you can navigate through the search results:</p>
<ul>
<li><p><code>n</code>: Go to the next match in the same direction (forward if <code>/</code>, backward if <code>?</code>).</p>
</li>
<li><p><code>N</code>: Go to the previous match in the opposite direction (backward if <code>/</code>, forward if <code>?</code>).</p>
</li>
</ul>
<h3 id="heading-replace-commands"><strong>Replace Commands</strong></h3>
<p>Once you've located the word or pattern you want to replace, Vim provides several commands for replacing text.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Command (In command mode)</td><td>Description</td></tr>
</thead>
<tbody>
<tr>
<td><code>/search_word</code></td><td>Searches for the given word and moves the cursor to its first occurrence below the current cursor position.</td></tr>
<tr>
<td><code>:s/search_word/replace_word</code></td><td>Replaces the first occurrence of <code>search_word</code> with <code>replace_word</code> in the current line.</td></tr>
<tr>
<td><code>:s/search_word/replace_word/g</code></td><td>Replaces all occurrences of <code>search_word</code> with <code>replace_word</code> in the current line.</td></tr>
<tr>
<td><code>:%s/search_word/replace_word</code></td><td>Replaces the first occurrence of <code>search_word</code> with <code>replace_word</code> in the entire file.</td></tr>
<tr>
<td><code>:%s/search_word/replace_word/g</code></td><td>Replaces all occurrences of <code>search_word</code> with <code>replace_word</code> in the entire file.</td></tr>
</tbody>
</table>
</div><p>Here’s an example:</p>
<p>In Vim, the <code>/Tanishka</code> pattern searches for an exact, case-sensitive match of the word "Tanishka."</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1736795075490/1ecbc6f4-65ef-46a9-841d-dbb3251f8ec7.png" alt="1ecbc6f4-65ef-46a9-841d-dbb3251f8ec7" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>To replace "Tanishka" with another word, like "Linux," you can use the substitution command like this: <code>:s/Tanishka/Linux</code>:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1736794982127/c9dffdba-c250-4601-8e3b-950d875908f8.png" alt="c9dffdba-c250-4601-8e3b-950d875908f8" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>By default, this command replaces only the first occurrence of "Tanishka" in the line where the cursor is located.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1736794997175/9831423d-4aab-43a1-9b06-408fb5dd4828.png" alt="9831423d-4aab-43a1-9b06-408fb5dd4828" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>If you want to replace all occurrences of "Tanishka" in the same line, you need to add the <code>g</code> (global) flag after the replacement string like this: <code>:s/Tanishka/Linux/g</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1736795009744/c53d0de2-b7b4-4154-baaa-3d28fb3c29db.png" alt="c53d0de2-b7b4-4154-baaa-3d28fb3c29db" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>This ensures that every instance of "Tanishka" in the current line is replaced with "Linux."</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1736795017539/dac817e5-8130-44d4-8f09-d887e42cc859.png" alt="dac817e5-8130-44d4-8f09-d887e42cc859" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>Similarly, the <code>%</code> symbol is used to specify the <strong>entire file</strong> when performing a substitution. Here's how it works in combination with the substitution command:</p>
<ol>
<li><p><strong>Replace the first occurrence in each line of the file:</strong></p>
<ul>
<li><code>:%s/Tanishka/Linux</code>: This command replaces only the first occurrence of "Tanishka" in each line of the file.</li>
</ul>
</li>
<li><p><strong>Replace all occurrences in the entire file:</strong></p>
<ul>
<li><code>:%s/Tanishka/Linux/g</code>: The addition of the <code>g</code> (global) flag ensures that all occurrences of "Tanishka" in every line of the file are replaced with "Linux."</li>
</ul>
</li>
</ol>
<h2 id="heading-how-to-read-files-using-more-and-less"><strong>How to Read Files using</strong> <code>more</code> <strong>and</strong> <code>less</code></h2>
<h3 id="heading-the-cat-command">The <code>cat</code> command</h3>
<p>The cat command is often used to read file content.</p>
<p>For example:</p>
<pre><code class="lang-bash">cat file.txt <span class="hljs-comment"># Displays content of file</span>
</code></pre>
<p>While the <code>cat</code> command is a straightforward tool for viewing file contents, its simplicity often falls short when working with large files or when precise navigation is required. That’s where the <code>more</code> and <code>less</code> commands come into play, offering enhanced functionality for viewing and navigating text efficiently.</p>
<h3 id="heading-the-more-command">The <code>more</code> Command</h3>
<p>The <code>more</code> command allows you to view files one screen at a time, making it a significant upgrade from <code>cat</code> when dealing with large files. But it comes with limitations in terms of backward navigation and advanced features.</p>
<p>Here’s the syntax for <code>more</code>:</p>
<pre><code class="lang-bash">more [FILENAME]
</code></pre>
<p>And here’s an example:</p>
<pre><code class="lang-bash">more file.txt <span class="hljs-comment"># Displays content of file.txt one page at a time</span>
</code></pre>
<p>Keys used while viewing:</p>
<ol>
<li><p>Spacebar: Moves forward by one page</p>
</li>
<li><p>Enter: Moves forward by one line</p>
</li>
<li><p>b: Moves back by one page</p>
</li>
<li><p>q: Quit and exit file content</p>
</li>
</ol>
<h3 id="heading-the-less-command">The <code>less</code> Command</h3>
<p>The <code>less</code> command is often considered a superior alternative to <code>more</code> due to its advanced navigation capabilities and flexibility. Unlike <code>more</code>, <code>less</code> allows both forward and backward navigation, making it ideal for reviewing large files or logs.</p>
<p>Here’s its syntax:</p>
<pre><code class="lang-bash">less [FILENAME]
</code></pre>
<p>And here’s an example:</p>
<pre><code class="lang-bash">less file.txt <span class="hljs-comment"># Displays content of file.txt one page at a time</span>
</code></pre>
<p>Keys used while viewing:</p>
<ol>
<li><p>Spacebar: Moves forward by one page</p>
</li>
<li><p>Enter: Moves forward by one line</p>
</li>
<li><p>b: Moves back by one page</p>
</li>
<li><p>Up/Down arrow key: Moves up or down by one line</p>
</li>
<li><p>q: Quit and exit less</p>
</li>
</ol>
<p>The only major difference between the <code>more</code> and <code>less</code> commands is that the less command allows bidirectional navigation, so it’s typically more convenient to use.</p>
<h2 id="heading-text-filters"><strong>Text Filters</strong></h2>
<p>A <strong>text filter</strong> in Linux is a command-line utility that processes text data by modifying, extracting, or formatting it before outputting the result.</p>
<h3 id="heading-horizontal-filters">Horizontal filters</h3>
<p>Horizontal filtering focuses on extracting, manipulating, or displaying specific lines of a file or command output. Common tools include <code>head</code>, <code>tail</code>, and <code>grep</code>.</p>
<ol>
<li><p><code>head</code>: The head command displays the first few lines of a file. By default, it shows the first 10 lines. Here’s its syntax:</p>
<pre><code class="lang-bash"> head [OPTIONS] [FILENAME]
</code></pre>
<p> And here’s an example of how to use it:</p>
<pre><code class="lang-bash"> head file.txt <span class="hljs-comment"># Displays first ten lines from file.txt</span>
 head -n 5 file.txt <span class="hljs-comment"># Displays first five lines from file.txt</span>
</code></pre>
</li>
<li><p><code>tail</code>: The tail command displays the last few lines of a file. By default, it shows the last 10 lines. Here’s its syntax:</p>
<pre><code class="lang-bash"> tail [OPTIONS] [FILENAME]
</code></pre>
<p> And here’s an example:</p>
<pre><code class="lang-bash"> tail file.txt <span class="hljs-comment"># Displays last ten lines from file.txt</span>
 tail -n 5 file.txt <span class="hljs-comment"># Displays last five lines from file.txt</span>
</code></pre>
</li>
<li><p><code>grep</code>: The grep command searches for patterns within a file or input. It filters out lines that match a given pattern. Here’s its syntax:</p>
<pre><code class="lang-bash"> grep [OPTIONS] [PATTERN] [FILENAME]
</code></pre>
<p> Options:</p>
<ul>
<li><p><code>-i</code>: Case-insensitive search.</p>
</li>
<li><p><code>-v</code>: Invert the match (exclude matching lines).</p>
</li>
<li><p><code>-n</code>: Show line numbers of matches.</p>
</li>
</ul>
</li>
</ol>
<p>    Example</p>
<pre><code class="lang-bash">    grep Tanishka data.txt <span class="hljs-comment"># Displays lines that have 'Tanishka' in them</span>
    grep -i Tanishka data.txt <span class="hljs-comment"># Displays lines that have 'Tanishka' irrespective of case</span>
    grep -v Tanishka data.txt <span class="hljs-comment"># Displays lines that do not have 'Tanishka' in them</span>
    grep -n Tanishka data.txt <span class="hljs-comment"># Displays lines that have 'Tanishka' in them along with number line</span>
</code></pre>
<h3 id="heading-vertical-filters">Vertical Filters</h3>
<ol>
<li><p><code>cut</code>: The cut command displays selected parts of lines from each file based on delimiters, byte positions, or character fields. Here’s its syntax:</p>
<pre><code class="lang-bash"> cut [OPTION] [FILENAME]
</code></pre>
<p> It also comes with various options:</p>
<ul>
<li><p><code>-c</code>: Extract specific characters.</p>
</li>
<li><p><code>-b</code>: Extract specific bytes.</p>
</li>
<li><p><code>-d</code>: Specify a custom delimiter (default is tab).</p>
<ul>
<li><code>cut -d ":" -f 2 file.txt</code> → Second field separated by <code>:</code>.</li>
</ul>
</li>
<li><p><code>-f</code>: Extract specific fields.</p>
<ul>
<li><code>cut -d "," -f 1,3 file.csv</code> → Fields 1 and 3 from a CSV.</li>
</ul>
</li>
</ul>
</li>
</ol>
<p>    Example:</p>
<pre><code class="lang-bash">    cut -c 1-10 Sample.txt <span class="hljs-comment"># Displays characters from position 1 to 10</span>
    cut -c 5 Sample.txt <span class="hljs-comment"># Displays character at position 5</span>
    cut -c 3,5 Sample.txt <span class="hljs-comment"># Displays characters from position 3 and 5 only</span>
    cut -d <span class="hljs-string">" "</span> -f 1 Sample.txt <span class="hljs-comment"># Displays first field separated by a space</span>
    cut -d <span class="hljs-string">" "</span> -f 2 Sample.txt <span class="hljs-comment"># Displays second field separated by a space</span>
    cut -d <span class="hljs-string">" "</span> -f 3 Sample.txt <span class="hljs-comment"># Displays third field separated by a space</span>
    cut -d <span class="hljs-string">" "</span> -f 1-3 Sample.txt <span class="hljs-comment"># Displays first to third fields separated by a space</span>
    cut -d <span class="hljs-string">" "</span> -f 1,3 Sample.txt <span class="hljs-comment"># Displays first and third fields separated by a space</span>
    cut -d <span class="hljs-string">":"</span> -f 5 /etc/passwd <span class="hljs-comment"># Displays fifth field separated by : in /etc/passwd</span>
</code></pre>
<h2 id="heading-text-summarization-tool-wc"><strong>Text Summarization Tool:</strong> <code>wc</code></h2>
<p>The <code>wc</code> (word count) command is used to display the number of lines, words, characters, or bytes in a file or input. It is a simple yet powerful utility you can use to summarize text content.</p>
<p>Here’s its syntax:</p>
<pre><code class="lang-bash">wc [OPTION] [FILENAME]
</code></pre>
<p>And here are its options:</p>
<ul>
<li><p><code>-l</code>: Displays the number of lines.</p>
</li>
<li><p><code>-w</code>: Displays the number of words.</p>
</li>
<li><p><code>-c</code>: Displays the number of bytes.</p>
</li>
<li><p><code>-m</code>: Displays the number of characters (useful for multibyte characters).</p>
</li>
<li><p><code>-L</code>: Displays the length of the longest line.</p>
</li>
</ul>
<p>Example:</p>
<pre><code class="lang-bash">wc Sample.txt <span class="hljs-comment"># Displays line count, word count, and byte count in Sample.txt</span>
wc -w Sample.txt <span class="hljs-comment"># Displays number of words in Sample.txt</span>
wc -l Sample.txt <span class="hljs-comment"># Displays number of lines in Sample.txt</span>
wc -L Sample.txt <span class="hljs-comment"># Displays number of characters in longest line in Sample.txt</span>

wc -c Sample.txt <span class="hljs-comment"># Displays number of bytes in Sample.txt (Actual storage size)</span>
wc -m Sample.txt <span class="hljs-comment"># Displays number of characters in Sample.txt (Actual number of characters regardless of enoing)</span>

<span class="hljs-comment"># ABCD😄</span>
wc -c above.txt <span class="hljs-comment"># "ABCD" = 4 bytes + "😄" = 4 bytes. 4 + 4 = 8 bytes</span>
wc -m above.txt <span class="hljs-comment"># "ABC" = 4 + "😄" = 1 byte. 4 + 1 = 5 bytes</span>
</code></pre>
<h2 id="heading-final-words">Final Words</h2>
<p>In this article, we covered the basics of using Vim, a powerful and flexible text editor. We started with how to open a file in Vim and then you learned about its modes. You also learned how to navigate through files, edit text, and use features like search and replace to save time. We also explored a helpful summarization tool.</p>
<p>If you're new to Linux and want to build a strong foundation, check <a target="_blank" href="https://www.freecodecamp.org/news/guide-to-rhel-linux-basics/">my previous article</a> where I cover the basics of Linux, including essential commands and tips for beginners. It’s a perfect starting point to complement what you’ve learned about Vim here!</p>
<p>Keep practising these commands, and soon they'll become second nature to you. Mastery comes with repetition, so continue experimenting and applying these fundamentals in real-world scenarios.</p>
<p>Stay tuned for more articles. Get ready to take your RHEL skills to the next level.</p>
<p><a target="_blank" href="https://linktr.ee/tanishkamakode">Let’s connect!</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Getting Started with RHEL: A Beginner’s Guide to Linux Basics ]]>
                </title>
                <description>
                    <![CDATA[ Imagine an operating system so reliable that it powers the world’s biggest servers, the fastest supercomputers, and even the cloud infrastructure of leading tech companies. Welcome to Red Hat Enterprise Linux (RHEL) — the backbone of modern IT system... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/guide-to-rhel-linux-basics/</link>
                <guid isPermaLink="false">67813ff98eada5cd9c2f7dc7</guid>
                
                    <category>
                        <![CDATA[ Linux ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Tanishka Makode ]]>
                </dc:creator>
                <pubDate>Fri, 10 Jan 2025 15:42:49 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1738685031729/c2dbcf09-c903-4eeb-b97a-0deb3a50385b.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Imagine an operating system so reliable that it powers the world’s biggest servers, the fastest supercomputers, and even the cloud infrastructure of leading tech companies. Welcome to Red Hat Enterprise Linux (RHEL) — the backbone of modern IT systems.</p>
<p>Whether you’re a complete novice exploring Linux for the first time or an experienced professional looking to brush up on your basics, you’re in the right place. This tutorial is your starting point to uncover the power, stability, and versatility of RHEL.</p>
<p>But what makes RHEL stand out in the crowded Linux ecosystem? Why do companies like Google, Amazon, and NASA rely on it? Let’s dive in and explore everything you need to know to begin your journey with Red Hat Enterprise Linux.</p>
<h3 id="heading-what-well-cover">What we’ll cover:</h3>
<ol>
<li><p><a class="post-section-overview" href="#heading-a-little-backstory">A Little Backstory</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-makes-linux-special">What Makes Linux Special?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-why-red-hat-enterprise-linux">Why Red Hat Enterprise Linux?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-set-up-your-practice-environment-for-linux-commands">How to Set Up Your Practice Environment for Linux Commands</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-introduction-to-basic-linux-commands">Introduction to Basic Linux Commands</a></p>
</li>
</ol>
<h2 id="heading-a-little-backstory">A Little Backstory</h2>
<p>Have you ever wondered where it all began? Before there was Linux, there was <strong>UNIX</strong>, a revolutionary operating system created in the 1970s that changed the way computers worked. Designed for stability, multitasking, and scalability, UNIX became the foundation upon which modern operating systems were built.</p>
<p>Fast forward to 1991, when a 21-year-old Finnish computer science student named Linus Torvalds at the University of Helsinki decided to create his own operating system kernel as a hobby project. Little did he know, this hobby would evolve into Linux, a game-changing open-source operating system that would redefine the tech world.</p>
<p>Now here’s the fun part: how did Linux get its name? Originally, Linus wanted to call it “Freax” (a combination of “free,” “freak,” and “Unix”). But when he uploaded the project files to a server managed by his friend Ari Lemmke, Ari thought “Freax” didn’t sound appealing enough. So, without telling Linus, Ari named the directory “Linux” instead — a clever blend of <strong>Linus + Unix</strong>. And the rest, as they say, is history.</p>
<h2 id="heading-what-makes-linux-special">What Makes Linux Special?</h2>
<p>Unlike traditional operating systems, Linux was open-source, meaning anyone could view, modify, and distribute the code freely. This sparked a wave of innovation, allowing developers around the world to create their own versions of Linux, tailored to different needs.</p>
<p>What truly sets Linux apart is the global community of developers and enthusiasts who constantly improve and innovate. This collaborative approach ensures that Linux stays at the forefront of technology, evolving with the needs of its users.</p>
<p>Today, Linux isn’t just one operating system — it’s an entire family of distributions (or distros). From user-friendly versions like Ubuntu and Fedora to enterprise-grade solutions like RHEL, there’s a Linux for everyone. In this article, we’ll focus on RHEL and why it’s a great choice for certain projects.</p>
<p>If you want to explore the fascinating variety of Linux distros, you can check out this <a target="_blank" href="https://en.wikipedia.org/wiki/Linux_distribution">Wikipedia page on Linux distributions</a> to see just how diverse the Linux ecosystem is.</p>
<h3 id="heading-why-red-hat-enterprise-linux">Why Red Hat Enterprise Linux?</h3>
<p>Red Hat Enterprise Linux (RHEL) is like the reliable, no-nonsense friend you call when you're organizing a big, important event.</p>
<p>Sure, you could ask your fun but unpredictable friends (like open-source Linux distros) to help, but there's always a chance they'll forget the chairs or crash halfway through the party.</p>
<p>RHEL, on the other hand, is built for stability and comes with a professional support team that’s on call 24/7 to fix anything that goes wrong. It’s tested thoroughly to make sure it works perfectly with all the tools and gadgets big companies use, so there are no surprises.</p>
<p>RHEL’s blend of reliability, security, performance, and support makes it the go-to operating system for enterprises, cementing its importance in the IT landscape.</p>
<p>Here’s a summary of RHEL’s benefits and features:</p>
<h4 id="heading-1-enterprise-grade-stability-and-reliability"><strong>1. Enterprise-Grade Stability and Reliability</strong></h4>
<p>RHEL is designed to meet the demands of mission-critical workloads, ensuring systems run consistently and predictably. Its long lifecycle support ensures businesses can rely on it without worrying about frequent upgrades or compatibility issues. This makes it an ideal choice for applications where downtime is unacceptable.</p>
<h4 id="heading-2-comprehensive-security-features"><strong>2. Comprehensive Security Features</strong></h4>
<p>Security is paramount in enterprise environments, and RHEL excels with robust features such as SELinux (Security-Enhanced Linux) and regular security updates. The proactive approach to identifying and addressing vulnerabilities helps organizations comply with industry regulations and maintain the integrity of their systems.</p>
<h4 id="heading-3-scalability-and-performance-optimization"><strong>3. Scalability and Performance Optimization</strong></h4>
<p>RHEL is optimized to deliver high performance for a wide range of hardware architectures and workloads, including cloud, on-premises, and hybrid setups. Its ability to scale efficiently makes it suitable for small-scale applications as well as large data centers and enterprise-grade workloads.</p>
<h4 id="heading-4-extensive-ecosystem-and-professional-support"><strong>4. Extensive Ecosystem and Professional Support</strong></h4>
<p>RHEL benefits from Red Hat’s extensive ecosystem of certified hardware, software, and cloud providers. Enterprises have access to a wealth of tested and certified solutions, along with 24/7 support from Red Hat. This ensures any technical issues are resolved promptly, minimizing downtime and enhancing productivity.</p>
<h2 id="heading-how-to-set-up-your-practice-environment-for-linux-commands">How to Set Up Your Practice Environment for Linux Commands</h2>
<p>Before we jump into learning and practising Linux commands, you’ll need to set up an environment where you can run these commands. Here are three great options to consider:</p>
<h3 id="heading-1-using-the-terminal-on-your-linux-machine">1. <strong>Using the Terminal on Your Linux Machine</strong></h3>
<p>If you’re already using Linux, the terminal is your go-to interface for interacting with the system. All Linux commands are executed here, and it’s the ideal environment to start practising.</p>
<p>You can open the terminal and directly type your commands to see them in action.</p>
<h3 id="heading-2-using-vmware-or-oracle-virtualbox">2. Using <strong>VMware or Oracle VirtualBox</strong></h3>
<p>If you don’t want to install Linux directly on your main machine, using a virtual machine (VM) is a great solution. Virtualization tools like VMware or Oracle VirtualBox allow you to run a full Linux distribution as a guest operating system without affecting your primary system. This way, you can experiment freely in an isolated environment.</p>
<p><strong>How to use a VM:</strong></p>
<ul>
<li><p>Install <a target="_blank" href="https://blogs.vmware.com/workstation/2024/05/vmware-workstation-pro-now-available-free-for-personal-use.html">VMware Workstation Player</a> or <a target="_blank" href="https://www.virtualbox.org/wiki/Downloads?">Oracle VirtualBox</a> on your computer.</p>
</li>
<li><p>Download the RHEL ISO Image. You can obtain the RHEL ISO by following these steps:</p>
<ol>
<li><p>Register for a Red Hat Developer Account (it’s free):</p>
<ul>
<li><p>Go to the Red Hat Developer Program.</p>
</li>
<li><p>Create an account (it’s free for individual developers).</p>
</li>
<li><p>After registering, sign in to your Red Hat account.</p>
</li>
</ul>
</li>
<li><p>Download the ISO:</p>
<ul>
<li><p>Visit the RHEL Download Page after logging in.</p>
</li>
<li><p>Choose the ISO image for RHEL (you may select the latest version).</p>
</li>
<li><p>Click Download and save the ISO file on your local system.</p>
</li>
</ul>
</li>
</ol>
</li>
</ul>
<p>Once your VM is running, you can use it to practice commands and explore Linux.</p>
<h3 id="heading-3-killercoda-an-online-linux-environment">3. <strong>KillerCoda: An Online Linux Environment</strong></h3>
<p>If you’re looking for an entirely online solution, KillerCoda is a fantastic option. It provides an interactive Linux terminal right in your browser, so you don’t need to install anything on your local machine.</p>
<p>Visit the <a target="_blank" href="https://killercoda.com/pawelpiwosz/course/linuxFundamentals">KillerCoda</a> website and you will see scenario-based lessons.</p>
<p>Now you should be all set.</p>
<h2 id="heading-introduction-to-basic-linux-commands">Introduction to Basic Linux Commands</h2>
<p>One of the key features that makes Linux so versatile is its command-line interface (CLI). This is where you can interact with the system by typing commands. These commands allow you to perform a variety of tasks like managing files, directories, system resources, and much more.</p>
<p>Now, we’ll explore some essential Linux commands that every beginner should know. These commands are simple yet powerful tools that can help you navigate and manage your Linux environment efficiently.</p>
<h3 id="heading-basic-linux-commands">Basic Linux Commands</h3>
<p><strong>1.</strong> <code>echo</code></p>
<p>The <code>echo</code> command is used to display text or variables to the terminal. It is one of the most commonly used commands in Linux and is helpful for displaying messages, variable values, and even system information.</p>
<p><code>echo</code> syntax:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> [OPTION] [STRING]
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> Hello <span class="hljs-comment"># Prints 'Hello' on terminal</span>
<span class="hljs-built_in">echo</span> -n Hey <span class="hljs-comment"># Does not output a trailing newline</span>

name=<span class="hljs-string">"Tanishka"</span>
<span class="hljs-built_in">echo</span> <span class="hljs-string">"Hello, <span class="hljs-variable">$name</span>"</span> <span class="hljs-comment"># Prints variables</span>
</code></pre>
<p>Option <code>-e</code> allows echo commands to enable escape sequences.</p>
<p>Here are some other options you can use with <code>echo</code>:</p>
<ol>
<li><p><code>\n</code> – New line: Moves the output to the next line.</p>
</li>
<li><p><code>\t</code> – Tab: Adds a tab space.</p>
</li>
<li><p><code>\v</code> – Vertical Tab: Adds a tab as the cursor moves to the next vertical position.</p>
</li>
<li><p><code>\b</code> – Backspace: Removes the last character.</p>
</li>
<li><p><code>\\</code> – Backslash: Prints a backslash.</p>
</li>
</ol>
<p>Example:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> -e <span class="hljs-string">"Hello World\nThis is a new line."</span>
<span class="hljs-comment"># Hello World</span>
<span class="hljs-comment"># This is a new line.</span>

<span class="hljs-built_in">echo</span> -e <span class="hljs-string">"Hello World\tThis is tabbed."</span>
<span class="hljs-comment"># Hello World    This is tabbed.</span>

<span class="hljs-built_in">echo</span> -e <span class="hljs-string">"Hello\vWorld\vThis is vertically spaced."</span>
<span class="hljs-comment"># Hello</span>
<span class="hljs-comment">#       World</span>
<span class="hljs-comment">#             This is vertically spaced.</span>

<span class="hljs-built_in">echo</span> -e <span class="hljs-string">"This is a backslash: \\"</span>
<span class="hljs-comment"># This is a backslash: \</span>
</code></pre>
<p><strong>2. whoami</strong></p>
<p>The <code>whoami</code> command is used to display the username of the currently logged-in user.</p>
<p><code>whoami</code> syntax:</p>
<pre><code class="lang-bash">whoami
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash">whoami <span class="hljs-comment">#tanishkamakode</span>
</code></pre>
<p><strong>3.</strong> <code>pwd</code></p>
<p>The <code>pwd</code> command is used to display the current working directory.</p>
<p><code>pwd</code> syntax:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">pwd</span> [OPTION]
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">pwd</span> <span class="hljs-comment"># /home/tanishkamakode</span>
<span class="hljs-built_in">pwd</span> -L <span class="hljs-comment"># Displays logical current working directory i.e. shows symlinks (shortcut path ,if exists)</span>
<span class="hljs-built_in">pwd</span> -P <span class="hljs-comment"># Displays physical current working directory i.e. shows resolved path (original path of shortcut ,if exists)</span>
</code></pre>
<p><strong>4.</strong> <code>ls</code></p>
<p>The <code>ls</code> command is used to list the files and directories in the current working directory or specified directory.</p>
<p><code>ls</code> syntax:</p>
<pre><code class="lang-bash">ls [OPTION] [PATH]
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash">ls <span class="hljs-comment"># Lists files and directories at current working directory</span>
</code></pre>
<p>Here are some options you can use with <code>ls</code>:</p>
<ul>
<li><p><code>ls -l</code>: Lists detailed information about files and directories</p>
</li>
<li><p><code>ls -lh</code>: Lists detailed information about files and directories with size in human readable format</p>
</li>
<li><p><code>ls -a</code>: Lists all hidden files</p>
</li>
<li><p><code>ls -R</code>: Lists recursive content of directory</p>
</li>
</ul>
<p><strong>5.</strong> <code>date</code></p>
<p>The <code>date</code> command is used to display or set the system date and time.</p>
<p><code>date</code> syntax:</p>
<pre><code class="lang-bash">date [OPTION] [FORMAT_SPECIFIER]
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash">date <span class="hljs-comment"># Displays current date and time</span>
date +<span class="hljs-string">"%d/%m/%Y"</span> <span class="hljs-comment"># Displays date month year</span>
date +<span class="hljs-string">"%H:%M:%S"</span> <span class="hljs-comment"># Displays hours minutes seconds</span>
date -u <span class="hljs-comment"># Displays date in UTC time</span>
date --<span class="hljs-built_in">set</span> <span class="hljs-string">"2024-06-05"</span> <span class="hljs-comment"># Sets date to given YYYY-MM-DD</span>
date -d <span class="hljs-string">"yesterday"</span> <span class="hljs-comment"># Displays yesterday's date</span>
date -d <span class="hljs-string">"tomorrow"</span> <span class="hljs-comment"># Displays tomorrow's date</span>
date -d <span class="hljs-string">"7 days"</span> <span class="hljs-comment"># Displays date of 7 days from today</span>
</code></pre>
<p>Options you can use with the date command:</p>
<ol>
<li><p><code>-u</code>: Displays date and time in UTC.</p>
</li>
<li><p><code>-d</code>: Displays or sets the date/time to a specific string (e.g., "yesterday", "7 days ago").</p>
</li>
<li><p><code>%d</code>: Day of the month (01 to 31).</p>
</li>
<li><p><code>%m</code>: Month of the year (01 to 12).</p>
</li>
<li><p><code>%y</code>: Last two digits of the year (00 to 99).</p>
</li>
<li><p><code>%Y</code>: Full year (for example, 2025).</p>
</li>
</ol>
<pre><code class="lang-bash">date -u <span class="hljs-comment"># Displays date in UTC time</span>
date -d <span class="hljs-string">"yesterday"</span> <span class="hljs-comment"># Displays yesterday's date</span>
date -d <span class="hljs-string">"tomorrow"</span> <span class="hljs-comment"># Displays tommorow's date</span>
date -d <span class="hljs-string">"7 days"</span> <span class="hljs-comment"># Displays date of 7 days from today</span>
date +<span class="hljs-string">"%d/%m/%Y"</span> <span class="hljs-comment"># Displays date month year</span>
date +<span class="hljs-string">"%H:%M:%S"</span> <span class="hljs-comment"># Displays hours minutes seconds</span>
</code></pre>
<p><strong>6.</strong> <code>cal</code></p>
<p>The <code>cal</code> command is used to display calendar details. If no options are given, the current month is displayed.</p>
<p><code>cal</code> syntax:</p>
<pre><code class="lang-bash">cal [OPTIONS]
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash">cal <span class="hljs-comment"># Displays current month calendar</span>
cal --highlight <span class="hljs-comment"># Highlights current date</span>
</code></pre>
<p>Options you can use with the <code>cal</code> command:</p>
<ol>
<li><p><code>--highlight</code>: Highlights the current date in the calendar.</p>
</li>
<li><p><code>-3</code>: Displays the previous, current, and next month.</p>
</li>
<li><p><code>-m</code>: Displays the current month in a multi-line format.</p>
</li>
<li><p><code>-y</code>: Displays the calendar for the entire year.</p>
</li>
<li><p><code>-A [N]</code>: Displays N months ahead of the current month.</p>
</li>
<li><p><code>-B [N]</code>: Displays N months before the current month.</p>
</li>
<li><p><code>cal [year]</code>: Displays the calendar for the entire year.</p>
</li>
<li><p><code>cal [month] [year]</code>: Displays the calendar for the specified month and year.</p>
</li>
</ol>
<pre><code class="lang-bash">cal 2024 <span class="hljs-comment"># Displays the calendar for all months of 2024</span>
cal 06 2024 <span class="hljs-comment"># Displays the calendar for the 6th month (June) of 2024</span>
cal -m <span class="hljs-comment"># Displays the current month in multi-line format</span>
cal -A 3 <span class="hljs-comment"># Displays the 3 months ahead of the current month</span>
cal -B 2 <span class="hljs-comment"># Displays the 2 months before the current month</span>
</code></pre>
<p><strong>7.</strong> <code>nl</code></p>
<p>The <code>nl</code> command is used to add line number to file content.</p>
<p><code>nl</code> syntax:</p>
<pre><code class="lang-bash">nl [OPTIONS] [FILENAME]
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash">nl file.txt <span class="hljs-comment"># Displays file content with line numbers</span>
nl -b a file.txt <span class="hljs-comment"># Numbers all lines</span>
nl -b t file.txt <span class="hljs-comment"># Number non-empty lines only</span>
nl -s <span class="hljs-string">') '</span> file.txt <span class="hljs-comment"># Adds a separator between the line number and the content -</span>
<span class="hljs-comment"># 1) First line</span>
<span class="hljs-comment"># 2) Second line</span>
</code></pre>
<p>As you can see in the code above, there are other options you can use with the <code>nl</code> command, too.</p>
<h3 id="heading-file-creation-and-handling-commands">File Creation and Handling Commands</h3>
<p><strong>1.</strong> <code>touch</code></p>
<p>The <code>touch</code> command is used to create an empty file or update the last modified time if a file exists.</p>
<p><code>touch</code> syntax:</p>
<pre><code class="lang-bash">touch [OPTIONS] [FILENAME]
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash">touch file.txt <span class="hljs-comment"># Creates a single file - file.txt</span>
touch file1.txt file2.txt file3.txt <span class="hljs-comment"># Creates multiple files</span>
touch file{1..10}.txt <span class="hljs-comment"># Creates files with given range names (file1.txt file2.txt upto file10.txt)</span>
</code></pre>
<p><strong>2.</strong> <code>cat</code></p>
<p>The <code>cat</code> command concatenates files and also displays the content of files.</p>
<p><code>cat</code> syntax:</p>
<pre><code class="lang-bash">cat [OPTIONS] [FILENAME]
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash">cat file.txt <span class="hljs-comment"># Displays content of file.txt</span>
cat file1.txt file2.txt &gt; merged.txt <span class="hljs-comment"># Overrides content of two files in merged.txt</span>
cat file1.txt &gt;&gt; file2.txt <span class="hljs-comment"># Appends content of first file to second file</span>
cat -n file.txt <span class="hljs-comment"># Displays the content along with line numbers</span>

cat &gt; file.txt OR cat &gt;&gt; file.txt <span class="hljs-comment"># &gt; for overriding, &gt;&gt; for appending</span>
<span class="hljs-comment"># This allows you to create a new file with a prompt to enter the content</span>
<span class="hljs-comment"># If file already exists, teminal will read the content you enter.</span>
<span class="hljs-comment"># Once you’re done with writing content,</span>
<span class="hljs-comment"># press Ctrl + D (detach).</span>
<span class="hljs-comment"># Or Ctrl + C but make sure you enter this on new line</span>
<span class="hljs-comment"># or else current line content will not be appended to the file.</span>
</code></pre>
<h3 id="heading-directory-creation-and-handling">Directory Creation and Handling</h3>
<p><strong>1.</strong> <code>mkdir</code></p>
<p>The <code>mkdir</code> command is used to create a directory.</p>
<p><code>mkdir</code> syntax:</p>
<pre><code class="lang-bash">mkdir [OPTIONS] [DIRECTORYNAME]
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash">mkdir folder <span class="hljs-comment"># Creates a single directory</span>
mkdir fol1 fol2 fol3 <span class="hljs-comment"># Creates multiple directories</span>
mkdir fol{1..10} <span class="hljs-comment"># Creates directories with given range names</span>
mkdir -p /myData/data <span class="hljs-comment"># Creates nested directories</span>
ls -R /myData <span class="hljs-comment"># Verify if nested directories created</span>
mkdir -v fol1 fol2 fol3 <span class="hljs-comment"># Verbose mode i.e confirmation of directory creation on terminal</span>
</code></pre>
<p><strong>2.</strong> <code>cd</code></p>
<p>The <code>cd</code> command is used to change the directory – that is, to navigate between directories.</p>
<p><code>cd</code> syntax:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">cd</span> [DIRECTORY]
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">cd</span> myFolder <span class="hljs-comment"># Relative path, starting from current directroy</span>
<span class="hljs-built_in">cd</span> /home/myFolder <span class="hljs-comment"># Absolute path, starting from root /</span>
<span class="hljs-built_in">cd</span> .. <span class="hljs-comment"># Goes to one level above current directory</span>
<span class="hljs-built_in">cd</span> ../.. <span class="hljs-comment"># Goes to two level above current directory</span>
<span class="hljs-built_in">cd</span> OR <span class="hljs-built_in">cd</span> ~ <span class="hljs-comment"># Goes to home directory</span>
<span class="hljs-built_in">cd</span> - <span class="hljs-comment"># Switched to directory you were in previously</span>
</code></pre>
<h3 id="heading-copy-move-and-remove-files-and-directories">Copy, Move, and Remove Files and Directories</h3>
<p><strong>1.</strong> <code>cp</code></p>
<p>The <code>cp</code> command is used to copy files and directories from one location to another.</p>
<p><code>cp</code> syntax:</p>
<pre><code class="lang-bash">cp [OPTIONS] [SOURCE] [DESTINATION]
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash">cp myFile.txt /home/newFolder <span class="hljs-comment"># Copies myFile.txt to newFolder</span>
cp myFile1.txt myFile2.txt /home/newFolder <span class="hljs-comment"># Copies multiple files to newFolder</span>
cp -r oldData /home/newData <span class="hljs-comment"># Recursively copies content of oldData directory to newData directory</span>
cp -i file.txt /home/Folder <span class="hljs-comment"># Asks for confirmation while overriding file.txt that already exists in Folder</span>
cp -v oldData /home/newData <span class="hljs-comment"># Verbose output i.e. confirmation of copying the directory </span>
cp -f file.txt /newFolder <span class="hljs-comment"># Copies the file forecfully</span>
</code></pre>
<p><strong>2.</strong> <code>mv</code></p>
<p>The <code>mv</code> command is used to move files and directories from one location to another. It is also used to rename a file or a directory.</p>
<p><code>mv</code> syntax:</p>
<pre><code class="lang-bash">mv [OPTIONS] [SOURCE] [DESTINATION]
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash">mv myFile.txt /home/newFolder <span class="hljs-comment"># Moves myFile to newFolder</span>
mv myFile1.txt myFile2.txt /home/newFolder <span class="hljs-comment"># Moves multiple files to newFolder</span>
mv -i file.txt /home/sample <span class="hljs-comment"># Asks before overriding the file.txt that already exists in sample</span>
mv -v oldData /home/sample <span class="hljs-comment"># Verbose mode i.e. confirmation of moving directory oldData in sample directory</span>
mv oldFile.txt newFile.txt <span class="hljs-comment"># Renames the file</span>
</code></pre>
<p><strong>3.</strong> <code>rm</code></p>
<p>The <code>rm</code> command is used to remove files and directories.</p>
<p><code>rm</code> syntax:</p>
<pre><code class="lang-bash">rm [OPTIONS] [FILENAME OR DIRECTORYNAME]
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash">rm file.txt <span class="hljs-comment"># Removes single file</span>
rm file1.txt file2.txt <span class="hljs-comment"># Removes multiple files</span>
rm emptyDir <span class="hljs-comment"># Won't work for empty directory (Next command will handle this case!)</span>
rm -r myData <span class="hljs-comment"># Removed a non-empty directory recursively</span>
rm -r -i myData <span class="hljs-comment"># Asks for confirmation before deleting each file</span>
rm -r -f myData <span class="hljs-comment"># Removes a non-empty directory recursively without confirmation</span>
rm -r -f -v myData <span class="hljs-comment"># Removes a non-empty directory recursively without confirmation in verbose mode</span>
</code></pre>
<p><strong>4.</strong> <code>rmdir</code></p>
<p>The <code>rmdir</code> command is used to remove empty directories only.</p>
<p><code>rmdir</code> syntax:</p>
<pre><code class="lang-bash">rmdir [OPTIONS] [FILENAME OR DIRECTORYNAME]
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash">rmdir emptyDir <span class="hljs-comment"># Removes empty directory emptyDir</span>
rmdir myDir1 myDir2 myDir3 <span class="hljs-comment"># Removes multiple empty directories</span>
rmdir myDir <span class="hljs-comment"># Won't work for non-empty directories (Use 'rm -r dir_name' for this case!)</span>
</code></pre>
<h2 id="heading-final-words">Final Words</h2>
<p>Congratulations! You've successfully learned the basics of Red Hat Enterprise Linux (RHEL) and the essential commands that form the foundation of Linux systems.</p>
<p>Keep practicing these commands, and soon they'll become second nature to you. Mastery comes with repetition, so continue experimenting and applying these fundamentals in real-world scenarios.</p>
<p>Stay tuned for more articles. Get ready to take your RHEL skills to the next level.</p>
<p><a target="_blank" href="https://linktr.ee/tanishkamakode">Let’s connect!</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ React Fundamentals – JSX, Components, and Props Explained ]]>
                </title>
                <description>
                    <![CDATA[ React is a popular JavaScript library for building user interfaces. And in order to create complex and efficient web applications, you'll need to understand its fundamental concepts. In this tutorial, we will be covering three essential concepts of R... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/react-fundamentals/</link>
                <guid isPermaLink="false">66d461493a8352b6c5a2ab13</guid>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Tanishka Makode ]]>
                </dc:creator>
                <pubDate>Fri, 07 Apr 2023 16:32:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/04/Blog-1-Cover--2-.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>React is a popular JavaScript library for building user interfaces. And in order to create complex and efficient web applications, you'll need to understand its fundamental concepts.</p>
<p>In this tutorial, we will be covering three essential concepts of React – JSX, components, and props.</p>
<p>To get started, you should be familiar with:</p>
<ol>
<li><p>JavaScript Basics</p>
</li>
<li><p>Destructuring of arrays and objects</p>
</li>
<li><p>ES6 modules</p>
</li>
</ol>
<p>So, if you are new to React or want to brush up on the basics, read on.</p>
<p>Before getting started with React concepts, let's learn a bit about JSX - which is what you use to write React code.</p>
<h2 id="heading-what-is-jsx">What is JSX?</h2>
<p>JSX stands for JavaScript XML. It's an extension of the JavaScript language based on ES6. It's translated into regular JavaScript at runtime.</p>
<p>JSX allows us to write HTML in React which makes the process of writing HTML in your React apps much easier.</p>
<h3 id="heading-why-use-jsx">Why use JSX?</h3>
<p>JSX is not mandatory. It is totally up to you whether to use plain HTML or JSX. But the code blocks I'll share below will clarify the differnece between plain HTML and JSX and which one is preferable.</p>
<pre><code class="lang-JavaScript"><span class="hljs-comment">// Plain HTML</span>
<span class="hljs-keyword">const</span> myElement = React.createElement(<span class="hljs-string">'h1'</span>, { <span class="hljs-attr">style</span>:{<span class="hljs-attr">color</span>:<span class="hljs-string">"green"</span>} }, <span class="hljs-string">'I do not use JSX!'</span>);

<span class="hljs-keyword">const</span> root = ReactDOM.createRoot(<span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'root'</span>));
root.render(myElement);
</code></pre>
<pre><code class="lang-JavaScript"><span class="hljs-comment">// JSX</span>
<span class="hljs-keyword">const</span> myElement = <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>I Love JSX!<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span></span>;

<span class="hljs-keyword">const</span> root = ReactDOM.createRoot(<span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'root'</span>));
root.render(myElement);
</code></pre>
<p>As you can see in the first example, using plain HTML makes it a bit more difficult to create elements. We need to use a createElement method, then pass the element along with its style and its value.</p>
<p>On the other hand, JSX makes it much easier by simply using the element tag just as we write HTML and passing its value.</p>
<p>Because of these advantages, I'd strongly recommend using JSX.</p>
<h3 id="heading-jsx-rules">JSX Rules</h3>
<p>There are few rules to keep it mind while working with JSX:</p>
<ol>
<li><p>A React component name must be capitalized. Component names that do not begin with a capital letter are treated like built-in components.</p>
</li>
<li><p>JSX allows you to return only one element from a given component. This is known as a parent element.</p>
</li>
</ol>
<p>If you want to return multiple HTML elements, simply wrap all of them in a single <code>&lt;div&gt;&lt;/div&gt;</code>, <code>&lt;React.fragments&gt;&lt;React.fragments/&gt;</code>, <code>&lt;&gt;&lt;/&gt;</code> or any semnatic tag.</p>
<pre><code class="lang-JavaScript"><span class="hljs-keyword">const</span> App = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">return</span>
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Hello World!<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Tanishka here!<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
}
</code></pre>
<p>But this won't work, because <code>return</code> would be interpreted as a plain return statement. To avoid that, you need to encapsulate everything inside <code>( )</code>.</p>
<pre><code class="lang-JavaScript"><span class="hljs-keyword">const</span> App = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Hello World!<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Tanishka here!<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}
</code></pre>
<p>Now, this will work perfectly!</p>
<ol start="3">
<li>In JSX, every tag, including self closing tags, must be closed. In case of self closing tags you have to add a slash at the end (for example <code>&lt;img/&gt;</code>, <code>&lt;hr/&gt;</code>, and so on).</li>
</ol>
<pre><code class="lang-JavaScript"><span class="hljs-keyword">const</span> App = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"./assets/react.svg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">""</span> /&gt;</span>
    <span class="hljs-tag">&lt;/&gt;</span></span>
  );
}
</code></pre>
<ol start="4">
<li><p>Since JSX is closer to JavaScript than to HTML, the React DOM uses the camelCase naming convention for HTML attribute names. For example: <code>tabIndex</code>, <code>onChnage</code>, and so on.</p>
</li>
<li><p>"class" and "for" are reserved keywords in JavaScript, so use "className" and "forHTML" instead, respectively.</p>
</li>
</ol>
<h3 id="heading-how-to-use-css-in-jsx">How to use CSS in JSX</h3>
<p>While working with JavaScript we typically have a HTML file, a CSS file, and a JavaScript file, right? Simple. But while working with React, we use HTML (JSX) and JavaScript in the same file.</p>
<p>To add style to our components, we can either use inline CSS or external CSS.</p>
<p>Let's first see how inline CSS works in React.</p>
<p>JSX represents objects, that is key-value pairs – like a property name and its value. Always write the value in <code>" "</code> as we do in objects.</p>
<p>So when we're adding inline styles to JSX elements, we must add { } for object representation (outer { } is the convention).</p>
<pre><code class="lang-JavaScript"><span class="hljs-keyword">const</span> App = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{</span> { <span class="hljs-attr">color:</span> "<span class="hljs-attr">Red</span>" } }&gt;</span>Hello World!<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{</span> { <span class="hljs-attr">fontSize:</span> "<span class="hljs-attr">20px</span>" } }&gt;</span>Tanishka here!<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/&gt;</span></span>
  );
}
</code></pre>
<p>Here, if you look at style in isolation, you'll see it does look like an object:</p>
<pre><code class="lang-JavaScript">{
    <span class="hljs-attr">color</span>: <span class="hljs-string">"Red"</span>
}
</code></pre>
<p>Basically, use { } to add styles, use key-value pairs, and always write the value in " ".</p>
<p>Now, let's see how to use an external CSS file.</p>
<p>We simply create a .css file and import it in our .jsx file like this:</p>
<pre><code class="lang-JavaScript"><span class="hljs-keyword">import</span> <span class="hljs-string">'./style.css'</span>

<span class="hljs-comment">/* 
    Your code here
*/</span>
</code></pre>
<h3 id="heading-how-to-use-js-in-jsx">How to use JS in JSX</h3>
<p>We might need to use plain JavaScript to add logic to program rendering components. And to add plain JavaScript code in JSX, we need to write it inside curly brackets.</p>
<p>However, whatever we write inside curly brackets must be an expression. Statements are not allowed.</p>
<pre><code class="lang-JavaScript"><span class="hljs-keyword">const</span> App = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>My name is {const name = "Tanishka"}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;/&gt;</span></span>
  );
}
</code></pre>
<p>The above code is invalid.</p>
<p>Now, you might think <code>{const name = "Tanishka"}</code> is also JavaScript. How is this code block not valid? Because it is an initialization of <code>name</code> that is a statement and we cannot write statements inside curly brackets.</p>
<p>We can make a few changes in the above code block and it will be valid:</p>
<pre><code class="lang-JavaScript"><span class="hljs-keyword">const</span> App = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">return</span> (
  <span class="hljs-keyword">const</span> name = <span class="hljs-string">"Tanishka"</span>;
    <span class="xml"><span class="hljs-tag">&lt;&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>My name is {name}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;/&gt;</span></span>
  );
}
</code></pre>
<p>We initialized value of <code>name</code> outside the return block and just used the included varibale <code>name</code> inside curly brackets, where name has the assigned value of <code>"Tanishka"</code>. So now it is an expression and is valid.</p>
<p>Now that we know how to write code in React, let's learn what to write – that is, React's basic concepts.</p>
<h2 id="heading-what-are-components-in-react">What are Components in React?</h2>
<p>Components are independent and reusable blocks of code which work in isolation. The main advantage of components is that they help reduce redundancy.</p>
<p>You can think of a component as a lego brick. When you're building a website, you put many of these bricks together to create the whole.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/Img1-1.png" alt="Img1-1" width="600" height="400" loading="lazy"></p>
<p>We can classify components into two types: class components and functional components. I won't go into the details here, as that's a topic for another tutorial.</p>
<p>Just know that the downsides of using class components are that they come with a bunch of preloaded stuff inside them whether you want it or not. This makes them a bit more difficult to deal with.</p>
<p>The React team recommends that new apps should be built with functional components and hooks. So, you should really consider the functional component approach when working with a new React project. So that's what we'll focus on here.</p>
<h3 id="heading-how-to-create-a-functional-component-in-react">How to create a functional component in React</h3>
<pre><code class="lang-JavaScript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Greet</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Hello World!<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span></span>;
}
</code></pre>
<p>OR</p>
<pre><code class="lang-JavaScript"><span class="hljs-keyword">const</span> Greet = <span class="hljs-function">() =&gt;</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Hello World!<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span></span>
</code></pre>
<p>Wait, but aren't these just JavaScript functions? YES! Components are basically JavaScript functions which return a single HTML element. Conventionally, arrow functions are widely used.</p>
<p>And what are those funny looking tags? That's called JSX, which you'll learn more about in a minute.</p>
<h3 id="heading-how-to-nest-components-in-react">How to nest components in React</h3>
<p>In React, we can nest components inside one another. This helps in creating more complex User Interfaces. It also helps in getting rid of redundant code. The components that are nested inside parent components are called child components.</p>
<p>For example:</p>
<pre><code class="lang-JavaScript"><span class="hljs-keyword">const</span> Book = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Book name : Cracking The Coding Interview<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Author : Gayle Laakmann McDowell<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
};
</code></pre>
<p>Here, we have created a Book component. What if we want to create more such instances of the book component? This is when we can use nested components.</p>
<pre><code class="lang-JavaScript"><span class="hljs-keyword">const</span> BookList = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Book</span> /&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Book</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
};

<span class="hljs-keyword">const</span> Book = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Book name : Cracking The Coding Interview<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Author : Gayle Laakmann McDowell<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
};
</code></pre>
<p>In the above code block, we have created two components, Book and BookList. <code>Book</code> returns a div that has <code>Book name</code> and <code>author name</code> while <code>BookList</code> returns a div that contains two <code>book</code>s.</p>
<p>In this way, nesting helps us create multiple instances of a component to create complex User Interfaces easily.</p>
<h2 id="heading-how-props-work-in-react">How Props Work in React</h2>
<p>Props stand for properties. Props are like function arguments, and you send them into the component as attributes.</p>
<p>When we want to create multiple instances of a single component with various different values, we need to use props.</p>
<p>Let's go with our pevious example of Book and BookList:</p>
<p>For example:</p>
<pre><code class="lang-JavaScript"><span class="hljs-keyword">const</span> BookList = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Book</span> /&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Book</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
};

<span class="hljs-keyword">const</span> Book = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Book name : Cracking The Coding Interview<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Author : Gayle Laakmann McDowell<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
};
</code></pre>
<p>In this code block, we have hard-coded values of book name and author but that's not really helpful for other books.</p>
<p>We can think of a component like a function and props like arguements of that function. We simply provide some specific values for each component and use those values in the component body.</p>
<p>Let's first see how to pass props:</p>
<pre><code class="lang-JavaScript"><span class="hljs-keyword">const</span> BookList = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Book</span> <span class="hljs-attr">bookName</span> = <span class="hljs-string">"Cracking The Coding Interview"</span>
      <span class="hljs-attr">author</span> = <span class="hljs-string">"Gayle Laakmann McDowell"</span>/&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Book</span> <span class="hljs-attr">bookName</span> = <span class="hljs-string">"The Road to Learn React"</span>
      <span class="hljs-attr">author</span> = <span class="hljs-string">"Robert Wieruch"</span>/&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
};
</code></pre>
<p>Here, we simply created variable-like structures (bookName, author) and assigned their respective values to them. That's it! These are props.</p>
<p>Now, let's see how can we access them, that is use them in the component body:</p>
<pre><code class="lang-JavaScript"><span class="hljs-keyword">const</span> Book = <span class="hljs-function">(<span class="hljs-params">props</span>) =&gt;</span> {
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Book name : {props.bookName}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Author : {props.author}<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
};
</code></pre>
<p>Firstly, we need to use the keyword <code>'props'</code> in the parameter of an arrow function which will act as an object. Now we can access the props values just like we access object values – <code>object.property</code>.</p>
<p>That's why we used <code>'props.bookName'</code> and <code>'props.author'</code>. Every book will get it's respective value by doing this, thus perfectly creating multiple instances of the book component.</p>
<p>You can use props like this, but there's another way of accessing props. For this method, you need to be familiar with the concept of destructuring, that is accessing each and every element of an object.</p>
<pre><code class="lang-JavaScript"><span class="hljs-keyword">const</span> Book = <span class="hljs-function">(<span class="hljs-params">props</span>) =&gt;</span> {
  <span class="hljs-keyword">const</span> {bookName, author} = props;
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Book name : {bookName}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Author : {author}<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
};
</code></pre>
<p>We destructured the <code>'bookName'</code> and <code>'author'</code> and we used them as varibles instead of <code>'props.bookName'</code> and <code>'prop.author'</code>.</p>
<p>We could have directly detructured props in the parameter section. It would have looked like this:</p>
<pre><code class="lang-JavaScript"><span class="hljs-keyword">const</span> Book = <span class="hljs-function">(<span class="hljs-params">{bookName, author}</span>) =&gt;</span> {
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Book name : {bookName}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Author : {author}<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
};
</code></pre>
<p>It works just the same as the previous method but we just destructure the content of the props in the parameter section instead of doing it by declarations.</p>
<h3 id="heading-children-props">Children props</h3>
<p>Sometimes, we might come across situations in which we need to add a specific element to a particular instance of a component only. We pass the specific element between opening and closing tags of the component. In those cases, we use children props.</p>
<pre><code class="lang-JavaScript"><span class="hljs-keyword">const</span> BookList = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Book</span> <span class="hljs-attr">bookName</span> = <span class="hljs-string">"Cracking The Coding Interview"</span>
      <span class="hljs-attr">author</span> = <span class="hljs-string">"Gayle Laakmann McDowell"</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span> Read Now! <span class="hljs-tag">&lt;<span class="hljs-name">button</span>/&gt;</span>
      <span class="hljs-tag">&lt; <span class="hljs-attr">Book</span> /&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Book</span> <span class="hljs-attr">bookName</span> = <span class="hljs-string">"The Road to Learn React"</span>
      <span class="hljs-attr">author</span> = <span class="hljs-string">"Robert Wieruch"</span>/&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  );
};</span>
</code></pre>
<p>In the above code block, we want to display a button only for the first book instance. That's why we used a child component by passing the button between opening and closing tags.</p>
<p>Let's see how to access them:</p>
<pre><code class="lang-JavaScript"><span class="hljs-keyword">const</span> Book = <span class="hljs-function">(<span class="hljs-params">{bookName, author, children}</span>) =&gt;</span> {
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Book name : {bookName}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Author : {author}<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
      {children}
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
};
</code></pre>
<p>We simply add <code>'children'</code> in the paramters section and then used <code>'{children}'</code> in components wherever we want to place child props. In this case, I wanted to place that button below the information, so I used <code>'{children}'</code> after <code>'bookName'</code> and <code>'author'</code>.</p>
<p>This places a child prop between opening and closing tags only when it's specified. This serves our purpose.</p>
<p>When we want an element to be present only for a single instance of the component, we can use children props between component tags. Then again, we can either use <code>props.children</code> or destructure it and use it directly.</p>
<p>Let me show you how it will look:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/ChildrenProps.png" alt="ChildrenProps" width="600" height="400" loading="lazy"></p>
<p>As you can see, only the first instance has got the button below its information. So this is how children props come in handy.</p>
<h3 id="heading-key-props">Key Props</h3>
<p>A key is a special attribute you need to include when creating lists of elements in React. We use keys to give an identity to elements in lists. We need to specify an id or any unique value to each instance of a component to keep track of their addition or removal.</p>
<p>When you're chosing a key for the items in lists, try to use a unique id for every instance. If an id is not provided or for some reason you can't use the id, we can go with the index of the list.</p>
<pre><code class="lang-JavaScript"><span class="hljs-keyword">const</span> App = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">const</span> numbers = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>];
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;&gt;</span>
      {numbers.map((number) =&gt; {
        return <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>{number}<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>;
      })}
    <span class="hljs-tag">&lt;/&gt;</span></span>
  );
};
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/keyError.png" alt="keyError" width="600" height="400" loading="lazy"></p>
<p>In the above code block, we are simply iterating over a list of numbers. Everything works fine until we open console. It is full of red text - a warning that says - <code>'Warning: Each child in a list should have a unique "key" prop.'</code></p>
<p>In this case, we don't have any specified id, so we can use the index of the list by accessing the second argument of the map function, that is index.</p>
<pre><code class="lang-JavaScript"><span class="hljs-keyword">const</span> App = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">const</span> numbers = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>];
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;&gt;</span>
      {numbers.map((number, index) =&gt; {
        return <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">key</span>=<span class="hljs-string">{index}</span>&gt;</span> {number} <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>;
      })}
    <span class="hljs-tag">&lt;/&gt;</span></span>
  );
};
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/keyNoError.png" alt="keyNoError" width="600" height="400" loading="lazy"></p>
<p>This code block works fine and all warnings are gone now.</p>
<hr>
<h2 id="heading-wrapping-up">Wrapping up</h2>
<p>I hope this tutorial has been helpful in getting you started on your React journey. Happy coding !👩🏻‍💻✨</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
