<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: RB Punna</title>
    <description>The latest articles on DEV Community by RB Punna (@rb_punna_8806d923a560a5a9).</description>
    <link>https://dev.to/rb_punna_8806d923a560a5a9</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2157712%2F20e86e67-87eb-4ad5-85de-bedcae54b1ba.png</url>
      <title>DEV Community: RB Punna</title>
      <link>https://dev.to/rb_punna_8806d923a560a5a9</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rb_punna_8806d923a560a5a9"/>
    <language>en</language>
    <item>
      <title>Introduction to Shell Scripting: A Beginner’s Guide</title>
      <dc:creator>RB Punna</dc:creator>
      <pubDate>Wed, 09 Oct 2024 12:54:01 +0000</pubDate>
      <link>https://dev.to/rb_punna_8806d923a560a5a9/introduction-to-shell-scripting-a-beginners-guide-2k19</link>
      <guid>https://dev.to/rb_punna_8806d923a560a5a9/introduction-to-shell-scripting-a-beginners-guide-2k19</guid>
      <description>&lt;p&gt;Shell scripting is a powerful way to automate tasks in Linux environments. If you find yourself typing the same commands repeatedly, shell scripts allow you to bundle these commands into a single executable file. This is particularly useful in DevOps, system administration, and development, where automation is key.&lt;/p&gt;

&lt;p&gt;In this guide, we’ll cover the basics of shell scripting, from creating your first script to executing and managing file permissions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started with Shell Scripting
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Creating a Shell Script&lt;/strong&gt;&lt;br&gt;
To create a shell script, you need to start by creating an empty file. You can use the &lt;code&gt;touch&lt;/code&gt; command to create a new file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch test.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;.sh&lt;/code&gt; extension is optional but recommended to denote that this file is a shell script.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Listing Files and Understanding Manual Pages&lt;/strong&gt;&lt;br&gt;
After creating your script, you can list the files in the current directory using the &lt;code&gt;ls&lt;/code&gt; command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ls
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To understand the various options for a command, use the &lt;code&gt;man&lt;/code&gt; (manual) command. For example, to see the options for &lt;code&gt;ls&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;man ls
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Opening and Editing Shell Scripts&lt;/strong&gt;&lt;br&gt;
To start writing in your shell script, open the file using a text editor like &lt;code&gt;vi&lt;/code&gt; or &lt;code&gt;vim&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;Open an existing file or create a new one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vi test.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vim test2.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once inside the editor, press i to switch to insert mode and start typing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The First Line of Every Shell Script: Shebang (&lt;code&gt;#!/bin/bash&lt;/code&gt;)&lt;/strong&gt;&lt;br&gt;
Every shell script should begin with a shebang. This is a special line that tells the system which interpreter to use to execute the script. The most common shebang for Bash scripts is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tells the system to use the Bash shell to run the script. Note that &lt;code&gt;#!/bin/sh&lt;/code&gt; was commonly used, but as some systems have changed the default shell to dash, it’s safer to explicitly use &lt;code&gt;/bin/bash&lt;/code&gt; for compatibility.&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing Your First Shell Script
&lt;/h2&gt;

&lt;p&gt;Let’s start with something simple: printing text to the screen. Use the echo command in your script to display a message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
echo "My first shell script"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After saving this file (&lt;code&gt;:wq&lt;/code&gt; in vi/vim), you need to make the script executable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Making a Shell Script Executable
&lt;/h2&gt;

&lt;p&gt;By default, newly created scripts aren’t executable. You can grant execute permissions using the chmod command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod +x test.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you can run your script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./test.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alternatively, you can also execute the script using &lt;code&gt;sh&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sh test.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Working with File Permissions
&lt;/h2&gt;

&lt;p&gt;Linux uses a permission model that includes read (r), write (w), and execute (x) permissions for the file owner, group, and others. Here’s how to modify permissions for your shell scripts:&lt;/p&gt;

&lt;p&gt;-&lt;br&gt;
Give all permissions** (read, write, and execute) to everyone:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod 777 firstfile.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This grants full control to the user, group, and others.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Read-only permissions:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;chmod 444 firstfile.sh&lt;br&gt;
This allows users to read the file but not modify or execute it.&lt;/p&gt;
&lt;h2&gt;
  
  
  Understanding Numeric Permissions
&lt;/h2&gt;

&lt;p&gt;The numeric permissions in chmod correspond to:&lt;/p&gt;

&lt;p&gt;4 = Read&lt;br&gt;
2 = Write&lt;br&gt;
1 = Execute&lt;/p&gt;

&lt;p&gt;So, &lt;code&gt;chmod 777&lt;/code&gt; gives read, write, and execute permissions to everyone, while &lt;code&gt;chmod 444&lt;/code&gt; gives only read permissions.&lt;/p&gt;
&lt;h2&gt;
  
  
  Writing a More Complex Shell Script
&lt;/h2&gt;

&lt;p&gt;Let’s create a slightly more complex shell script that creates a directory and two files inside it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash

# Create a directory
mkdir myfolder

# Move into the new directory
cd myfolder

# Create two files
touch file1.txt file2.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save and exit the file, then give it execute permissions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod +x firstbash.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the script, and you’ll see that it creates the folder and files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./firstbash.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Essential Commands in Shell Scripting
&lt;/h2&gt;

&lt;p&gt;Here are some other important commands you can use in shell scripting:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disk Space Information:&lt;/strong&gt; Use df to check disk space usage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;df -h
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;CPU Information:&lt;/strong&gt; Use nproc to display the number of processing units available.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nproc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Memory Information:&lt;/strong&gt; Use free to check memory usage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;free -g
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;System Monitoring:&lt;/strong&gt; Use top to display active processes and resource usage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;top
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Stopping a Script:&lt;/strong&gt; Press &lt;code&gt;Ctrl + C&lt;/code&gt; to stop a running script or process.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Role of Shell Scripts in DevOps
&lt;/h2&gt;

&lt;p&gt;In DevOps, shell scripting plays a critical role in automating repetitive tasks such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Deploying applications&lt;/li&gt;
&lt;li&gt;Managing infrastructure&lt;/li&gt;
&lt;li&gt;Monitoring system resources&lt;/li&gt;
&lt;li&gt;Performing backups&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Automating these tasks reduces human error and ensures consistency in deployments, making shell scripts an essential tool for DevOps professionals.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Comments in Shell Scripts
&lt;/h2&gt;

&lt;p&gt;When writing longer scripts, it’s essential to add comments to explain different sections of your script. In Bash, comments begin with the # symbol:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash

# This is a comment
echo "This script demonstrates shell scripting"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Comments are ignored during execution but help others (or future you) understand your code better.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Shell scripting is a powerful way to automate and streamline tasks in a Linux environment. By learning the basics of scripting, from creating files to managing permissions, you’ll be able to simplify complex processes and boost your productivity.&lt;/p&gt;

&lt;p&gt;With commands like &lt;code&gt;chmod&lt;/code&gt;, &lt;code&gt;echo&lt;/code&gt;, and basic script structures, you're well on your way to mastering shell scripting. And as you grow in your Linux journey, you’ll find countless opportunities to use scripts to solve real-world problems in system administration, development, and DevOps.&lt;/p&gt;

&lt;p&gt;Now, it’s your turn: write your first shell script, experiment with the commands, and start automating your tasks today!&lt;/p&gt;

</description>
      <category>programming</category>
      <category>linux</category>
      <category>bash</category>
      <category>learning</category>
    </item>
    <item>
      <title>Unlocking Linux: A Beginner’s Guide to Essential Commands and Shell Scripting</title>
      <dc:creator>RB Punna</dc:creator>
      <pubDate>Thu, 03 Oct 2024 07:16:22 +0000</pubDate>
      <link>https://dev.to/rb_punna_8806d923a560a5a9/unlocking-linux-a-beginners-guide-to-essential-commands-and-shell-scripting-3690</link>
      <guid>https://dev.to/rb_punna_8806d923a560a5a9/unlocking-linux-a-beginners-guide-to-essential-commands-and-shell-scripting-3690</guid>
      <description>&lt;p&gt;&lt;strong&gt;Why Linux? Understanding the Power Behind the OS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Linux has steadily gained popularity over the years, especially in server environments, software development, and IT operations. What makes it so special? Here’s why Linux stands out:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Free&lt;/strong&gt;&lt;br&gt;
Linux is completely free! You don’t need to purchase expensive licenses or subscriptions to use it. It’s accessible to everyone.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Open Source&lt;/strong&gt;&lt;br&gt;
Linux’s open-source nature allows users to inspect, modify, and distribute the code. This fosters a global community of developers working to improve the system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Secure&lt;/strong&gt;&lt;br&gt;
With frequent updates and its permission-based architecture, Linux is one of the most secure operating systems available. It’s far less susceptible to viruses and malware than its competitors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Versatile Flavors&lt;/strong&gt;&lt;br&gt;
Linux comes in many distributions (distros) such as Ubuntu, CentOS, Debian, and Fedora, catering to different needs, from enterprise solutions to personal computing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Fast Performance&lt;/strong&gt;&lt;br&gt;
Linux’s lightweight structure makes it fast and resource-efficient. It’s especially suited for older hardware or systems requiring high performance, like servers.&lt;/p&gt;
&lt;h2&gt;
  
  
  Linux Shell: Where the Magic Happens
&lt;/h2&gt;

&lt;p&gt;The shell is the interface between the user and the Linux operating system. It’s where you enter commands and where most of your interaction with the system happens. Let’s dive into the essential Linux commands that every user should know.&lt;/p&gt;
&lt;h2&gt;
  
  
  Basic Navigation and Directory Management
&lt;/h2&gt;

&lt;p&gt;Linux treats everything as a file, even directories (folders), making navigation a core skill to master.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Understanding Your Current Location:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;pwd&lt;/code&gt; – Print Working Directory. Displays the path of your current directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pwd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Listing Files and Directories:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;ls&lt;/code&gt; – List the contents of a directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ls
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;ls -ltr&lt;/code&gt; – List files and directories in long format, showing file properties and sorted by time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ls -ltr
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Changing Directories:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;cd&lt;/code&gt; – Change directory. You can move between directories using this command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /path/to/directory     # Move to specific directory
cd ..                     # Move to parent directory
cd ../..                  # Move two directories up
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;cd directory1/directory2&lt;/code&gt; – Navigate through multiple directories in one go.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Creating Directories:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;mkdir&lt;/code&gt;– This command is used to create a new directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir my_new_directory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also create multiple directories at once:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir dir1 dir2 dir3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;mkdir -p&lt;/code&gt; – This option creates parent directories if they don’t already exist. For example, if you want to create a directory inside another directory that doesn't exist yet, use -p:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir -p parent_directory/child_directory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Removing Directories:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;rmdir&lt;/code&gt; – Removes an empty directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rmdir empty_directory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;rm -r&lt;/code&gt; – Removes a directory and its contents recursively.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rm -r directory_to_remove
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;File Management&lt;/strong&gt;&lt;br&gt;
Working with files is a daily task for every Linux user, and there are several commands that make this easy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Creating and Editing Files:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;touch&lt;/code&gt;– Create a new, empty file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch newfile.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;vi&lt;/code&gt; – Open or create a file and start editing with the vi text editor.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vi test.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Press &lt;strong&gt;i&lt;/strong&gt; to switch to insert mode and start typing.&lt;/li&gt;
&lt;li&gt;Press &lt;strong&gt;Esc&lt;/strong&gt; to exit insert mode.&lt;/li&gt;
&lt;li&gt;Type &lt;strong&gt;:wq!&lt;/strong&gt; to save and exit.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Viewing File Contents:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;cat&lt;/code&gt; – Display the contents of a file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat test.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;System Monitoring&lt;/strong&gt;&lt;br&gt;
Monitoring system resources and performance is crucial, especially in server environments or during heavy computation tasks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Checking Memory Usage:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;free -g&lt;/code&gt; – Display memory usage in gigabytes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;free -g
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Checking CPU Information:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;nproc&lt;/code&gt; – Display the number of CPU cores available.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nproc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Checking Disk Space:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;df -h&lt;/code&gt; – Display available disk space in a human-readable format.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;df -h
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Real-Time System Monitoring:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;top&lt;/code&gt; – Display real-time system information, including CPU and memory usage and running processes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;top
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Shell Scripting: Automating Tasks in Linux
&lt;/h2&gt;

&lt;p&gt;Linux is not just about running commands manually. Shell scripting allows you to automate repetitive tasks, making your life easier, especially in DevOps environments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Creating a Simple Shell Script:&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;&lt;strong&gt;Step 1: Create the script&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
Use the &lt;code&gt;touch&lt;/code&gt;command to create a script file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch myscript.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;strong&gt;Step 2: Edit the script&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
Open the script using &lt;code&gt;vi&lt;/code&gt;or &lt;code&gt;vim&lt;/code&gt;and add your commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vi myscript.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;strong&gt;Step 3: Add a Shebang&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
The shebang (&lt;code&gt;#!/bin/bash&lt;/code&gt;) at the top tells the system that this is a bash script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;strong&gt;Step 4: Add Commands&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
Write your commands under the shebang, like printing a message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo "Hello, Linux!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;strong&gt;Step 5: Save and exit&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
Press Esc and type :wq! to save and exit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Running the Shell Script:&lt;/strong&gt;&lt;br&gt;
Before running the script, give it execute permission:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod +x myscript.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now run the script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./myscript.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Managing File Permissions with chmod&lt;/strong&gt;&lt;br&gt;
In Linux, every file has three types of permissions: read, write, and execute. Using the chmod command, you can modify these permissions for the owner, group, and others. Let’s look at how you can manage file permissions using chmod with some practical examples:&lt;/p&gt;

&lt;p&gt;Each group has three types of access:&lt;/p&gt;

&lt;p&gt;Read (4) (r)&lt;br&gt;
Write (2) (w)&lt;br&gt;
Execute (1) (x)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Granting Read Permission:&lt;/strong&gt;&lt;br&gt;
To allow a user to read a file, you can use the +r option:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod +r myscript.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command gives read permission to the file myscript.sh.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Granting Write Permission:&lt;/strong&gt;&lt;br&gt;
To give write permission (allowing modification of the file), use the +w option:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod +w myscript.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This allows you or other users to edit the file myscript.sh.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Granting Execute Permission:&lt;/strong&gt;&lt;br&gt;
To make a script or program executable, use the +x option:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod +x myscript.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command allows the file myscript.sh to be run as an executable program.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Combining Permissions:&lt;/strong&gt;&lt;br&gt;
You can also combine multiple permissions in a single command. For example, to give read, write, and execute permissions to a file, use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod +rwx myscript.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or, using numeric notation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod 777 myscript.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This would grant read, write, and execute permissions to everyone.&lt;/p&gt;

&lt;h2&gt;
  
  
  DevOps and Shell Scripting: Why It’s Essential
&lt;/h2&gt;

&lt;p&gt;Shell scripting is the backbone of many DevOps operations. Here’s why:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Automating Repetitive Tasks:&lt;/strong&gt; From deploying applications to managing configurations, shell scripts reduce manual effort.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Efficiency:&lt;/strong&gt; By scripting routine tasks, you can improve the overall efficiency of the system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Monitoring and Maintenance:&lt;/strong&gt; Automate tasks like system monitoring, log rotation, backups, and more using shell scripts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus: Additional Useful Linux Commands
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Getting Command Options:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;man&lt;/code&gt; – The manual for any command. For example, man ls will show all the options for the ls command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;man ls
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. History of Commands:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;history&lt;/code&gt; – Display the list of commands you've previously entered.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;history
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Canceling a Running Command:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;Ctrl+C&lt;/code&gt; – Stop a running program in the terminal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Linux is a powerful and flexible operating system that rewards users who take the time to master its command-line interface. By learning and practicing the commands outlined in this post, you’ll unlock a world of potential — whether you’re navigating the file system, managing resources, or automating tasks through shell scripting.&lt;/p&gt;

&lt;p&gt;The key to becoming proficient in Linux is practice. So fire up your terminal, run these commands, and start exploring the endless possibilities that Linux offers!&lt;/p&gt;

&lt;p&gt;Thank you for reading..!! If you like the post, Clap and comment..!!&lt;/p&gt;

&lt;p&gt;If you feel any other important Linux command to be added, please mention in comment, I will try to add.&lt;/p&gt;

&lt;p&gt;I will also post another article on Shell Scripting soon here.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>linux</category>
      <category>bash</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
