<?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: Shiva Prasad Gajula</title>
    <description>The latest articles on DEV Community by Shiva Prasad Gajula (@gajulashivaprasad).</description>
    <link>https://dev.to/gajulashivaprasad</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%2F1092995%2F2c971963-1ef6-4cec-a426-81aafc2ac4f9.png</url>
      <title>DEV Community: Shiva Prasad Gajula</title>
      <link>https://dev.to/gajulashivaprasad</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gajulashivaprasad"/>
    <language>en</language>
    <item>
      <title>Mastering the Linux Command Line: Your Ultimate Cheat Sheet for Seamless Operations</title>
      <dc:creator>Shiva Prasad Gajula</dc:creator>
      <pubDate>Wed, 31 May 2023 11:04:01 +0000</pubDate>
      <link>https://dev.to/gajulashivaprasad/mastering-the-linux-command-line-your-ultimate-cheat-sheet-for-seamless-operations-1e</link>
      <guid>https://dev.to/gajulashivaprasad/mastering-the-linux-command-line-your-ultimate-cheat-sheet-for-seamless-operations-1e</guid>
      <description>&lt;p&gt;As programmers, we spend most of our time writing code to build software. However, when shifting that code to production, our coding skills may not be sufficient. In such cases, we rely on commands to accomplish various tasks, such as connecting to remote servers using SSH, checking file permissions, and editing/updating files on the server.&lt;/p&gt;

&lt;p&gt;In this blog post, we will explore some of the most commonly used commands in Linux-based systems that will make your deployment process a bit easier (although not necessarily a piece of cake 😜!).&lt;/p&gt;

&lt;p&gt;Since this article is a bit longer, I have divided it into the following sections.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;File commands&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Search Commands&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;System commands&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;User commands&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Permission commands&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Process commands&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Network and storage commands&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Compression commands&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;SSH and File transfer commands&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;File commands&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;As the word implies, this is everything to do with files and directories such as listing directories, printing the working folder, changing the folder, etc.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;pwd&lt;/code&gt; Stands for Print Working Directory. Prints the path of the current working directory starting from the root&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ls&lt;/code&gt; Displays the files and directories of the current working directory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ls Documents&lt;/code&gt; Displays the contents of the Documents directory&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ls /&lt;/code&gt; Displays the contents of the root directory&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ls ..&lt;/code&gt; Displays the contents of the parent directory(one level above)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ls ../..&lt;/code&gt; Displays the contents of the parent directory(two levels above)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ls ~&lt;/code&gt; Displays the contents of the user’s home directory (/home/user)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ls -d */&lt;/code&gt; Displays all the folders of the current working directory&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ls *&lt;/code&gt; Displays the contents along with the contents of subdirectories&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ls -R&lt;/code&gt; Displays the files and directories in the current working directory, including their corresponding sub-directories down to the last file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ls -s&lt;/code&gt; Displays the content with the size.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ls -l&lt;/code&gt; Displays the detailed content information, including file and directory permissions, the number of links pointing to the content, the user and group associated with the content, as well as the last modified date and time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ls -lh&lt;/code&gt; Similar to the above command, It represents the size of files and directories in a readable format, such as 100B for bytes or 4.0K for kilobytes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ls -a&lt;/code&gt; Displays the contents including hidden files&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ls -l -a&lt;/code&gt; or &lt;code&gt;ls -a -l&lt;/code&gt; or &lt;code&gt;ls -la&lt;/code&gt; or &lt;code&gt;ls -al&lt;/code&gt; Displays the contents including hidden information&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ls -t&lt;/code&gt; Displays the contents sorted by last modified date in descending order.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ls -tr&lt;/code&gt; Displays the contents sorted by last modified date in ascending order&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ls -S&lt;/code&gt; Displays the contents sorted by size in descending order&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ls -Sr&lt;/code&gt; Displays the contents sorted by size in ascending order&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ls &amp;gt; output.txt&lt;/code&gt; Displays contents and directories and writes to &lt;code&gt;output.txt&lt;/code&gt; file (Note: You can use any of the above-discussed flags and the ls command. such as &lt;code&gt;-s&lt;/code&gt;, &lt;code&gt;-R&lt;/code&gt; &lt;code&gt;-t&lt;/code&gt; etc.)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;mkdir test&lt;/code&gt; Creates a test directory in the current folder&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;cd test&lt;/code&gt; Changes the current working directory to test&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;cd ..&lt;/code&gt;  Move up to one directory&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;cd /&lt;/code&gt; Takes to the root directory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;cd&lt;/code&gt; Takes to the home directory&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;cd ~&lt;/code&gt; Takes to the home directory&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;clear&lt;/code&gt; Clears the terminal&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;touch file1.txt&lt;/code&gt; Creates a &lt;code&gt;file1.txt&lt;/code&gt; file in the current working directory&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;nano file1.txt&lt;/code&gt; Opens the &lt;code&gt;file1.txt&lt;/code&gt; file in the nano editor&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;cat file1.txt&lt;/code&gt; Shows the contents of &lt;code&gt;file1.txt&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;less file1.txt&lt;/code&gt; Shows less content of &lt;code&gt;file1.txt&lt;/code&gt; (Hit q to exit)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;mv file1.txt file2.txt&lt;/code&gt; Renames &lt;code&gt;file1.txt&lt;/code&gt; to &lt;code&gt;file2.txt&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;cp file1.txt file2.txt&lt;/code&gt;  Copy the contents of &lt;code&gt;file1.txt&lt;/code&gt; to &lt;code&gt;file2.txt&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;cp file1.txt ~/dir2/file2.txt&lt;/code&gt; Copy a file to a different path&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;rm file1.txt&lt;/code&gt; Deletes a file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;rmdir dir2&lt;/code&gt; Deletes a directory&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;rm -R dir2&lt;/code&gt; Deletes a directory with files&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Search Commands&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In this section, you will explore the commands that would help you to search for specific files, directories, or content within files&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;grep "five" file1.txt&lt;/code&gt; Search the text &lt;strong&gt;five&lt;/strong&gt; in &lt;code&gt;file1.txt&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;grep "five" blog/posts/file1.txt&lt;/code&gt; Search the text &lt;strong&gt;five&lt;/strong&gt; in &lt;code&gt;blog/posts/file1.txt&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;grep -r "five" blog&lt;/code&gt; Search in the blog directory and its child contents for text five&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;find -name file1.txt&lt;/code&gt; Search the file &lt;code&gt;file1.txt&lt;/code&gt; in the current working directory&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;find blog/posts -name 'file1.txt'&lt;/code&gt; Finds the file &lt;code&gt;file1.txt&lt;/code&gt; in the &lt;code&gt;blog/posts&lt;/code&gt; directory&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;find blog/posts -name 'file*'&lt;/code&gt; Finds the files prefix with ‘file’ in the &lt;code&gt;blog/posts&lt;/code&gt; directory&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;find -size +100M&lt;/code&gt; Finds the files which have more than 100 MB in size&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;System commands&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Linux provides a wide range of system commands that allow users to interact with their operating system, gather information, and perform various administrative tasks. These commands play a crucial role in managing and maintaining a Linux system effectively.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;uname -a&lt;/code&gt; Displays Linux system information&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;uname -r&lt;/code&gt; Displays kernel release information&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;uptime&lt;/code&gt; Displays how long the system has been running and the load average.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;uptime -p&lt;/code&gt; Same as above but displays the output in a pretty format&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;uptime -s&lt;/code&gt; Displays how long the system has been up&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;hostname&lt;/code&gt; Displays the system hostname&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;hostname -I&lt;/code&gt; Display all local IP addresses of the host&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;last reboot&lt;/code&gt; Displays the system reboot history&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;date&lt;/code&gt; Displays the current date&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;cal&lt;/code&gt; Displays the calendar&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;w&lt;/code&gt; Displays the users who are online&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;whoami&lt;/code&gt; Displays the logged-in user&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;history&lt;/code&gt; Shows the audit of the user&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;which curl&lt;/code&gt; Shows the curl application path(installation location)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;User commands&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;User management is a crucial aspect of Linux system administration. Linux provides a variety of commands to interact with user accounts, gather user-related information, and manage user privileges. These commands enable system administrators to effectively manage user accounts and ensure proper access control.&lt;/p&gt;

&lt;p&gt;In this section, we will delve into some essential user commands that can assist you in user management tasks.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;cat /etc/passwd&lt;/code&gt; Displays the list of users.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;getent passwd&lt;/code&gt; Displays the list of users.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;cat /etc/passwd&lt;/code&gt; command and &lt;code&gt;getent passwd&lt;/code&gt; command displays the list of users in the system. The output is typically presented in the following format&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;redis:x:112:119::/var/lib/redis:/usr/sbin/nologin&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The above line consists of seven fields, which are as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;redis&lt;/code&gt;: User name.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;x&lt;/code&gt;: Encrypted password (the letter "x" indicates that the actual password is stored in the &lt;code&gt;/etc/shadow&lt;/code&gt; file).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;112&lt;/code&gt;: User ID number (UID).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;119&lt;/code&gt;: User's group ID number (GID).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;/var/lib/redis&lt;/code&gt;: Full name of the user (GECOS).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;/usr/sbin/nologin&lt;/code&gt;: User home directory.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These commands provide important information about users on the system, such as their usernames, user IDs, group IDs, and home directories.&lt;/p&gt;

&lt;p&gt;Ok. As you saw the &lt;code&gt;cat /etc/passwd&lt;/code&gt; and &lt;code&gt;getent passwd&lt;/code&gt; commands will display the output with seven fields.&lt;/p&gt;

&lt;p&gt;However, you can also extract the part of the output by giving specific commands.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;awk -F: '{print $1, $2}' /etc/passwd&lt;/code&gt; Displays the first two fields out of 7 fields&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;cut -d: -f1,2,3 /etc/passwd&lt;/code&gt; Displays the first 3 fields out of 7 fields&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;sudo useradd test_user1&lt;/code&gt; Creates a new user called test_user1&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;sudo passwd test_user1&lt;/code&gt; Sets the new password for user test_user1&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;sudo useradd -m test_user2&lt;/code&gt; Creates a new user called test_user2 and also creates a test_user2 directory under the home directory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;sudo useradd -m -d /opt/test_user3 test_user3&lt;/code&gt; Creates a &lt;strong&gt;test_user3&lt;/strong&gt; user and also creates a &lt;strong&gt;test_user3&lt;/strong&gt; directory under opt directory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;sudo useradd -u 1600 test_user4&lt;/code&gt; Creates a &lt;strong&gt;test_user4&lt;/strong&gt; user with 1600 id&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;id -u test_user4&lt;/code&gt; Returns the id of the user&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;sudo useradd -g users login_user1&lt;/code&gt; Creates a new user and sets the login group to users&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;id -gn login_user1&lt;/code&gt; Displays the group name of the user&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;sudo useradd -g users -G user1,user2 login_user2&lt;/code&gt; Creates a new user called login_user2 and sets the primary group as users and secondary groups as user1, and user2.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;id login_user2&lt;/code&gt; Displays the userid, primary, and secondary group ids&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;sudo groupadd managers&lt;/code&gt; Creates a new group called managers&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;sudo chgrp managers file1.txt&lt;/code&gt; Changes the group to managers on &lt;code&gt;file1.txt&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;sudo usermod -aG managers login_user2&lt;/code&gt; Adds &lt;strong&gt;login_user2&lt;/strong&gt; to the managers group&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Permission commands&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Understanding Permissions in Linux In Linux, permissions play a crucial role in controlling access to files and directories. They define what actions users can perform on specific resources, such as reading, writing, or executing files&lt;/p&gt;

&lt;p&gt;For example, run the &lt;code&gt;ls -l&lt;/code&gt; command in any of the directories which have some content.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;drwxr-xr-x 1 777 shiva 4096 May 25 16:52 blog&amp;lt;br&amp;gt;-rw-r--r-- 1 shiva shiva 158 Jan 17 11:54 dump.rdb&amp;lt;br&amp;gt;drwxr-xr-x 1 shiva shiva 4096 May 25 12:52 shell-scripting&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You will see similar output in your terminal. Let’s consider the first 10 characters (&lt;code&gt;drwxr-xr-x&lt;/code&gt;) in the first line.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The first letter denotes the content type such as directory or file. &lt;code&gt;d&lt;/code&gt; refers to the directory &lt;code&gt;-&lt;/code&gt; refers to the file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The second three letters refer to the user permissions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The third three letters refer to the group permissions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The last three letters refer to the other's permissions&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;r&lt;/code&gt; read, &lt;code&gt;w&lt;/code&gt; write, &lt;code&gt;x&lt;/code&gt; execute, &lt;code&gt;-&lt;/code&gt; no permission&lt;/p&gt;

&lt;p&gt;&lt;code&gt;u&lt;/code&gt; user, &lt;code&gt;g&lt;/code&gt; group, &lt;code&gt;o&lt;/code&gt; other people from the outside world, &lt;code&gt;an&lt;/code&gt;all&lt;/p&gt;

&lt;p&gt;&lt;code&gt;+&lt;/code&gt; adds permissions, &lt;code&gt;-&lt;/code&gt; removes permissions, &lt;code&gt;=&lt;/code&gt; adds new permissions and overrides existing&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;chmod o+w file1.txt&lt;/code&gt; gives write access to the outside people on file1.txt&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;chmod o-w file1.txt&lt;/code&gt; removes write access for the outside people on file1.txt&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;chmod g+wr file1.txt&lt;/code&gt; gives read-and-write access to the groups&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;chmod u=rwx file1.txt&lt;/code&gt; gives read, write, and execute access to the user and overrides the existing permissions&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Absolute Numeric Mode&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;&lt;strong&gt;Number&lt;/strong&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;&lt;strong&gt;Permission Type&lt;/strong&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;&lt;strong&gt;Symbol&lt;/strong&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;0&lt;/p&gt;&lt;/td&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;No permission&lt;/p&gt;&lt;/td&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;&lt;code&gt;---&lt;/code&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;1&lt;/p&gt;&lt;/td&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;Execute&lt;/p&gt;&lt;/td&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;&lt;code&gt;--x&lt;/code&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;2&lt;/p&gt;&lt;/td&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;Write&lt;/p&gt;&lt;/td&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;&lt;code&gt;-w-&lt;/code&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;3&lt;/p&gt;&lt;/td&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;Execute + Write&lt;/p&gt;&lt;/td&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;&lt;code&gt;-wx&lt;/code&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;4&lt;/p&gt;&lt;/td&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;Read&lt;/p&gt;&lt;/td&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;&lt;code&gt;r--&lt;/code&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;5&lt;/p&gt;&lt;/td&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;Read + Execute&lt;/p&gt;&lt;/td&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;&lt;code&gt;r-x&lt;/code&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;6&lt;/p&gt;&lt;/td&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;Read + Write&lt;/p&gt;&lt;/td&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;&lt;code&gt;rw-&lt;/code&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;7&lt;/p&gt;&lt;/td&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;Read + Write + Execute&lt;/p&gt;&lt;/td&gt;
&lt;td colspan="1" rowspan="1"&gt;&lt;p&gt;&lt;code&gt;rwx&lt;/code&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;chmod 111 file1.txt&lt;/code&gt; gives execute access to the user, group, and others&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;chmod 750 file1.txt&lt;/code&gt; gives read+write+execute access to users and read+execute access to groups and no permissions to outside people.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;chmod -R 777 posts&lt;/code&gt; give read+write+execute access to users, groups, and others on the directory posts and their contents.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Process commands&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Processes are an integral part of any operating system, including Linux. They represent running programs or tasks that consume system resources. Linux provides a range of commands to manage processes efficiently, allowing users to monitor, control, and terminate them as needed.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ps&lt;/code&gt; displays currently running user processes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ps -ef&lt;/code&gt; displays currently running system processes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ps -ef grep 12693&lt;/code&gt; displays the process information of 12693&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;top&lt;/code&gt; shows the processes running(hit q to exit)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;htop&lt;/code&gt; alternative for the top (interactive process viewer)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;kill 24567&lt;/code&gt; kills the process 24567&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Network and storage commands&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Linux provides a variety of commands that enable users to interact with the network and storage components of their system. These commands allow you to gather network information, perform network diagnostics, manage storage devices, and retrieve files from the web. Understanding these commands can greatly enhance your ability to work with network and storage resources effectively.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ifconfig&lt;/code&gt; shows the network information&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;iwconfig&lt;/code&gt; shows wireless information&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ping&lt;/code&gt; &lt;code&gt;google.com&lt;/code&gt; returns the continuous response from the host&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;blkid&lt;/code&gt; shows the storage information&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;df&lt;/code&gt; shows the available and unavailable disk space&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;lsusb&lt;/code&gt; shows the connected devices list&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;lspci&lt;/code&gt; shows PCI information&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;wget&lt;/code&gt; &lt;code&gt;https://www.sample-videos.com/img/Sample-jpg-image-50kb.jpg&lt;/code&gt; downloads image file&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Compression commands&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Compression commands are indispensable when it comes to managing large sets of files or reducing file sizes for storage or transfer. Linux provides a wide range of compression commands that allow you to package files into archives, extract their contents, and compress them using various algorithms. Following are some of the example compression commands.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;tar cf testDir.tar testDir&lt;/code&gt; compress the &lt;code&gt;testDir&lt;/code&gt; and creates &lt;code&gt;testDir.tar&lt;/code&gt; file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;tar xf testDir.tar&lt;/code&gt; extract the contents of testDir.tar&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;tar czf testDir.tar.gz testDir&lt;/code&gt; creates gzip compressed tar file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;tar xzf testDir.tar.gz&lt;/code&gt; extract the compressed gzip file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;tar -tvf testDir.tar&lt;/code&gt; displays the contents of the tar file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;tar -tvf testDir.tar.gz&lt;/code&gt; displays the contents of gzip tar file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;tar -xf nodejs.tar.xs&lt;/code&gt; Extracts the contents of nodejs.tar.xs&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;SSH and File transfer commands&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Secure Shell (SSH) and file transfer commands are essential tools for remote access and transferring files between local and remote systems in Linux. SSH provides a secure encrypted connection, while file transfer commands enable efficient and secure file transfer over SSH. Following are some of the example SSH commands.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ssh&lt;/code&gt; &lt;code&gt;root@domain.com&lt;/code&gt; connect to the domain.com server with the root user (prompts for password)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;scp file1.txt&lt;/code&gt; &lt;code&gt;user1@domain.com&lt;/code&gt; &lt;code&gt;/tmp&lt;/code&gt; copies the file securely to the &lt;code&gt;tmp&lt;/code&gt; folder in the domain.com server&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;sudo scp -r&lt;/code&gt; &lt;code&gt;user1@domain.com:/var/www /temp&lt;/code&gt; copies files recursively from the server to the local machine&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ok. I know the list is too big. But, it is worth going through it. If you have these commands in your arsenal, you can definitely win the command line war.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>commands</category>
    </item>
    <item>
      <title>Mastering Shell Scripting: Your Ultimate Cheat Sheet for Efficient Automation</title>
      <dc:creator>Shiva Prasad Gajula</dc:creator>
      <pubDate>Wed, 31 May 2023 11:02:15 +0000</pubDate>
      <link>https://dev.to/gajulashivaprasad/mastering-shell-scripting-your-ultimate-cheat-sheet-for-efficient-automation-7o5</link>
      <guid>https://dev.to/gajulashivaprasad/mastering-shell-scripting-your-ultimate-cheat-sheet-for-efficient-automation-7o5</guid>
      <description>&lt;p&gt;Bash is a powerful scripting language used in the Linux terminal to automate tasks and perform various operations. Here are some essential commands and concepts to help you get started with Bash scripting.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Creating a script:&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Create a file name whatever you want. But, make sure it ends with &lt;code&gt;.sh&lt;/code&gt;. Open that file in your favorite text editor and write the first line to begin your shell script journey.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;my_script.sh&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;#! /bin/bash&lt;/code&gt; line is called the &lt;strong&gt;shebang&lt;/strong&gt; or &lt;strong&gt;hashbang&lt;/strong&gt;, and it is used to specify the interpreter to be used for executing the script. In this case, &lt;code&gt;#!/bin/bash&lt;/code&gt; indicates that the script should be interpreted and executed using the Bash shell.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Running the script:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Open your terminal and go to the directory where you created the script file. Then run the below command to execute the script&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;At this stage, you won't see any output since we have not written anything other than the &lt;strong&gt;shebang&lt;/strong&gt; line. Let's add some fun stuff.&lt;/p&gt;

&lt;h4&gt;
  
  
  Display statements:
&lt;/h4&gt;

&lt;p&gt;You can use the &lt;code&gt;echo&lt;/code&gt; command to print statements or messages in the terminal. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo &lt;/span&gt;Hello World
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will see &lt;code&gt;Hello World&lt;/code&gt; in your terminal&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Variables:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can assign values to variables in Bash using the assignment operator &lt;code&gt;(=)&lt;/code&gt;. Variable names are usually uppercase by convention and can contain letters, numbers, and underscores. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;NAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Shiva"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"My name is &lt;/span&gt;&lt;span class="nv"&gt;$NAME&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;User input:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To read user input in Bash, you can use the read command. It prompts you to enter a value and stores it in a variable. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;read&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="s2"&gt;"Enter your name: "&lt;/span&gt; NAME
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Hello &lt;/span&gt;&lt;span class="nv"&gt;$NAME&lt;/span&gt;&lt;span class="s2"&gt;, nice to meet you!s"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Gives you the following output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Enter your name: Shiva
Hello Shiva, &lt;span class="nb"&gt;nice &lt;/span&gt;to meet you!s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conditional Statements:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Bash supports various conditional statements to control the flow of your script. Here are a few examples:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Simple If Statement:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$NAME&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"Shiva"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;then
  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Your name is Shiva"&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;If Statement with Else:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$NAME&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"Shiva"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;then
  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Your name is Shiva"&lt;/span&gt;
&lt;span class="k"&gt;else
  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Your name is not Shiva"&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Else If Statement:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$NAME&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"Shiva"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;then
  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Your name is Shiva"&lt;/span&gt;
&lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$NAME&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"Jack"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;then
  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Your name is Jack"&lt;/span&gt;
&lt;span class="k"&gt;else
  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Your name is NOT Shiva or Jack"&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Below is an example of comparing two numbers using &lt;code&gt;-gt&lt;/code&gt; operator in the shell script&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;NUM1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;3 
&lt;span class="nv"&gt;NUM2&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;5
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$NUM1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;-gt&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$NUM2&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; 
&lt;span class="k"&gt;then 
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$NUM1&lt;/span&gt;&lt;span class="s2"&gt; is greater than &lt;/span&gt;&lt;span class="nv"&gt;$NUM2&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;else 
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$NUM1&lt;/span&gt;&lt;span class="s2"&gt; is less than &lt;/span&gt;&lt;span class="nv"&gt;$NUM2&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use any of the following operators to do comparisons in a shell script.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Equal to&lt;/strong&gt;: &lt;code&gt;==&lt;/code&gt; or &lt;code&gt;=&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Example: &lt;code&gt;[ "$var1" == "$var2" ]&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Checks if &lt;code&gt;$var1&lt;/code&gt; is equal to &lt;code&gt;$var2&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Not equal to&lt;/strong&gt;: &lt;code&gt;!=&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Example: &lt;code&gt;[ "$var1" != "$var2" ]&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Checks if &lt;code&gt;$var1&lt;/code&gt; is not equal to &lt;code&gt;$var2&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Greater than&lt;/strong&gt;: &lt;code&gt;&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Example: &lt;code&gt;[ "$var1" -gt "$var2" ]&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Checks if &lt;code&gt;$var1&lt;/code&gt; is greater than &lt;code&gt;$var2&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Greater than or equal to&lt;/strong&gt;: &lt;code&gt;-ge&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Example: &lt;code&gt;[ "$var1" -ge "$var2" ]&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Checks if &lt;code&gt;$var1&lt;/code&gt; is greater than or equal to &lt;code&gt;$var2&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Less than&lt;/strong&gt;: &lt;code&gt;&amp;lt;&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Example: &lt;code&gt;[ "$var1" -lt "$var2" ]&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Checks if &lt;code&gt;$var1&lt;/code&gt; is less than &lt;code&gt;$var2&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Less than or equal to&lt;/strong&gt;: &lt;code&gt;-le&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Example: &lt;code&gt;[ "$var1" -le "$var2" ]&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Checks if &lt;code&gt;$var1&lt;/code&gt; is less than or equal to &lt;code&gt;$var2&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Following is the example to check whether a file exists with the given or not&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;FILE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"test.txt"&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$FILE&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;then
  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$FILE&lt;/span&gt;&lt;span class="s2"&gt; exists"&lt;/span&gt;
&lt;span class="k"&gt;else
  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$FILE&lt;/span&gt;&lt;span class="s2"&gt; does not exist"&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Case Statement:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The case statement allows you to evaluate the value of a variable against multiple patterns and execute different blocks of code based on the matching pattern.&lt;/p&gt;

&lt;p&gt;Following is the example code snippet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;read&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="s2"&gt;"Are you 21 or over? Y/N "&lt;/span&gt; ANSWER
&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$ANSWER&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
    &lt;span class="o"&gt;[&lt;/span&gt;yY] &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;yY][eE][sS]&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"You can have a beer :)"&lt;/span&gt;
        &lt;span class="p"&gt;;;&lt;/span&gt;
    &lt;span class="o"&gt;[&lt;/span&gt;nN] &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;nN][oO]&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Sorry, no drinking"&lt;/span&gt;
        &lt;span class="p"&gt;;;&lt;/span&gt;
    &lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Please enter y/yes or n/no"&lt;/span&gt;
        &lt;span class="p"&gt;;;&lt;/span&gt;
&lt;span class="k"&gt;esac&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code produces the following output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Example 1&lt;/span&gt;
Are you 21 or over? Y/N y
You can have a beer :&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="c"&gt;# Example 2&lt;/span&gt;
Are you 21 or over? Y/N N
Sorry, no drinking
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Simple for loop&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The for loop allows you to iterate over a list of values and perform a set of actions for each value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;NAMES&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Brad Kevin Alice Mark"&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;NAME &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nv"&gt;$NAMES&lt;/span&gt;
&lt;span class="k"&gt;do
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Hello &lt;/span&gt;&lt;span class="nv"&gt;$NAME&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Following is the output of the above code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Hello Brad
Hello Kevin
Hello Alice
Hello MarkWhile loop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A while loop in a shell script allows you to repeatedly execute a block of code as long as a certain condition is true. Here is an example of for loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;LINE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1
&lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="nb"&gt;read&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; CURRENT_LINE
&lt;span class="k"&gt;do
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$LINE&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="nv"&gt;$CURRENT_LINE&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="o"&gt;((&lt;/span&gt;LINE++&lt;span class="o"&gt;))&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt; &amp;lt; &lt;span class="s2"&gt;"./contents.txt"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Functions:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In shell scripting, you can define and use functions to encapsulate a block of code that can be executed multiple times throughout your script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sayHello&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Hello World"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;# Call the function&lt;/span&gt;
sayHello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Function with parameters:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;greet&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Hello, I am &lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt; and I am &lt;/span&gt;&lt;span class="nv"&gt;$2&lt;/span&gt;&lt;span class="s2"&gt; years old"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;# Call the function and pass arguments&lt;/span&gt;
greet &lt;span class="s2"&gt;"Shiva"&lt;/span&gt; &lt;span class="s2"&gt;"26"&lt;/span&gt;
FUNCTION WITH PARAMS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Create a folder and write to a file&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;hello
&lt;span class="nb"&gt;touch&lt;/span&gt; &lt;span class="s2"&gt;"hello/world.txt"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Hello World"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"hello/world.txt"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Created hello/world.txt"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ok. In conclusion, this article covers basic shell scripting concepts anyone can begin with.&lt;/p&gt;

</description>
      <category>shell</category>
      <category>shellscript</category>
      <category>programming</category>
      <category>linux</category>
    </item>
  </channel>
</rss>
