<?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: Madhvi Patel</title>
    <description>The latest articles on DEV Community by Madhvi Patel (@madhvipatel).</description>
    <link>https://dev.to/madhvipatel</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%2F356266%2Feaa35855-286d-426f-bbcb-aaa7cdebb321.jpg</url>
      <title>DEV Community: Madhvi Patel</title>
      <link>https://dev.to/madhvipatel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/madhvipatel"/>
    <language>en</language>
    <item>
      <title>Basic of Shell Scripting</title>
      <dc:creator>Madhvi Patel</dc:creator>
      <pubDate>Sun, 03 Oct 2021 12:04:04 +0000</pubDate>
      <link>https://dev.to/madhvipatel/basic-of-shell-scripting-2dbe</link>
      <guid>https://dev.to/madhvipatel/basic-of-shell-scripting-2dbe</guid>
      <description>&lt;p&gt;&lt;code&gt;#! /bin/bash&lt;/code&gt;  This statement marks the start of shell script.&lt;/p&gt;

&lt;h2&gt;
  
  
  Echo command:
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Echo used for returning/printing the information on stdout(screen).&lt;/code&gt;&lt;br&gt;
echo Hello World!&lt;/p&gt;

&lt;h2&gt;
  
  
  Variables:
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Variables used for holding a value in memory. Should be Uppercase by convention. Any letters, numbers and underscores can be used. For accessing the variables, always use '$' or '${VAR-NAME}' in front of variable name.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;NAME="Adam"&lt;br&gt;
echo "My name is $NAME."&lt;br&gt;
echo "My name is ${NAME}."&lt;/p&gt;

&lt;h2&gt;
  
  
  User Input:
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;read command is used for taking the input from stdin.&lt;br&gt;
-p is used for prompting the text to the stdout.&lt;br&gt;
NAME is used as variable for capturing the user entered data.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;read -p "Enter your name:" NAME&lt;br&gt;
echo "Your name is ${NAME}."&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Incase you do not want to prompt any text at stdout then use following: Here read will read the user provided input and store it in variable NAME.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;read NAME&lt;br&gt;
echo "Your name is ${NAME}."&lt;/p&gt;

&lt;h2&gt;
  
  
  IF statement:
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;if condition then result and fi&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;if [ "$NAME" ==  "Thomas" ]&lt;br&gt;
then &lt;br&gt;
      echo "Your name is Thomas"&lt;br&gt;
fi&lt;/p&gt;

&lt;h2&gt;
  
  
  IF-ELSE statement:
&lt;/h2&gt;

&lt;p&gt;if [ "$NAME" ==  "Thomas" ]&lt;br&gt;
then &lt;br&gt;
      echo "Your name is Thomas"&lt;br&gt;
else&lt;br&gt;
      echo "Your name is something else"&lt;br&gt;
fi&lt;/p&gt;

&lt;h2&gt;
  
  
  IF-ELSE-IF-ELSE statement:
&lt;/h2&gt;

&lt;p&gt;if [ "$NAME" ==  "Thomas" ]&lt;br&gt;
then &lt;br&gt;
      echo "your name is Thomas"&lt;br&gt;
elif  [ "$NAME" ==  "Fred" ]&lt;br&gt;
then &lt;br&gt;
       echo "your name is Fred"&lt;br&gt;
else&lt;br&gt;
       echo "your name is not Thomas nor Fred"&lt;br&gt;
fi&lt;/p&gt;

&lt;h2&gt;
  
  
  COMPARISON
&lt;/h2&gt;

&lt;p&gt;NUM1=40&lt;br&gt;
NUM2=35&lt;/p&gt;

&lt;p&gt;if [ "$NUM1"  -gt  "$NUM2" ]&lt;br&gt;
then&lt;br&gt;
      echo "$NUM1 is greater than $NUM2."&lt;br&gt;
else&lt;br&gt;
      echo "$NUM2 is greater than $NUM1."&lt;br&gt;
fi&lt;/p&gt;

&lt;h3&gt;
  
  
  Different comparison operators:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;val1 -eq val2 =&amp;gt; Returns true if the values are equal&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;val1 -ne val2 =&amp;gt; Returns true if the values are not equal&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;val1 -gt val2 =&amp;gt; Returns true if val1 is greater than val2&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;val1 -ge val2 =&amp;gt; Returns true if val1 is greater than or equal to val2&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;val1 -lt val2 =&amp;gt; Returns true if val1 is less than  val2&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;val1 -le val2 =&amp;gt; Returns true if val1 is less than or   equal to val2&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  CASE STATEMENT:
&lt;/h2&gt;

&lt;p&gt;read -p "Is your age above 18? Y/N" ANSWER&lt;br&gt;
case "$ANSWER" in&lt;br&gt;
    [yY]|[yY][eE][sS])&lt;br&gt;
          echo "You are allowed to have drinks"&lt;br&gt;
          ;;&lt;br&gt;
    [nN]|[nN][oO])&lt;br&gt;
          echo "You can enjoy juices"&lt;br&gt;
          ;;&lt;br&gt;
    *)&lt;br&gt;
          echo "Enter your age"&lt;br&gt;
          ;;&lt;br&gt;
esac&lt;/p&gt;

&lt;h2&gt;
  
  
  FILE CONDITIONS:
&lt;/h2&gt;

&lt;p&gt;FILE="file.txt"&lt;br&gt;
if [ -e "$FILE" ]&lt;br&gt;
then &lt;br&gt;
      echo "$FILE exists"&lt;br&gt;
else &lt;br&gt;
      echo "$FILE does not exists"&lt;br&gt;
fi&lt;/p&gt;

&lt;h3&gt;
  
  
  Different file operators:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;-d file =&amp;gt; True if file is an directory&lt;/li&gt;
&lt;li&gt;-e file =&amp;gt; True if file exists&lt;/li&gt;
&lt;li&gt;-f file =&amp;gt; True if provided string is file&lt;/li&gt;
&lt;li&gt;-g file =&amp;gt; True if the group id is set on file&lt;/li&gt;
&lt;li&gt;-r file =&amp;gt; True if file is readable&lt;/li&gt;
&lt;li&gt;-s file =&amp;gt; True if file has non zero size&lt;/li&gt;
&lt;li&gt;-u file =&amp;gt; True if the user id is set on a file&lt;/li&gt;
&lt;li&gt;-w file =&amp;gt; True if file is writtable&lt;/li&gt;
&lt;li&gt;-x file =&amp;gt; True is file is an executable&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  FOR LOOP:
&lt;/h2&gt;

&lt;p&gt;NAMES="Brad Kevin Alice Mark"&lt;br&gt;
for NAME in $NAMES&lt;br&gt;
  do &lt;br&gt;
      echo "Hello $NAME"&lt;br&gt;
  done&lt;/p&gt;

&lt;h2&gt;
  
  
  WHILE LOOP:
&lt;/h2&gt;

&lt;p&gt;LINE=1&lt;br&gt;
WHILE read -r CURRENT_LINE&lt;br&gt;
  do &lt;br&gt;
      echo "$LINE: $CURRENT_LINE"&lt;br&gt;
      ((LINE++))&lt;br&gt;
done &amp;lt; "./shell-script.sh"&lt;/p&gt;

&lt;h2&gt;
  
  
  FUNCTION:
&lt;/h2&gt;

&lt;p&gt;function helloWorld(){&lt;br&gt;
      echo "Hello World"&lt;br&gt;
}&lt;br&gt;
helloWorld &lt;br&gt;
&lt;code&gt;helloWorld will call the function.&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  FUNCTION WITH PARAMS:
&lt;/h2&gt;

&lt;p&gt;function intro(){&lt;br&gt;
      echo "Hello I am $1 and I am $2 years old"&lt;br&gt;
}&lt;br&gt;
intro "Brad" "36"&lt;br&gt;
&lt;code&gt;intro Brad will call the function with param Brad. You can pass in multiple params and access them using numbers $1, $2 and so on.&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  CREATE FOLDER AND WRITE TO A FILE
&lt;/h2&gt;

&lt;p&gt;mkdir hello&lt;br&gt;
touch hello/world.txt&lt;br&gt;
echo "Hello World" &amp;gt;&amp;gt; hello/world.txt&lt;br&gt;
echo "created hello/world.txt"&lt;/p&gt;

</description>
      <category>programming</category>
      <category>linux</category>
      <category>shellscript</category>
    </item>
    <item>
      <title>Linux Basic Commands Cheetsheet</title>
      <dc:creator>Madhvi Patel</dc:creator>
      <pubDate>Sun, 03 Oct 2021 11:48:17 +0000</pubDate>
      <link>https://dev.to/madhvipatel/linux-basic-commands-cheetsheet-4ae7</link>
      <guid>https://dev.to/madhvipatel/linux-basic-commands-cheetsheet-4ae7</guid>
      <description>&lt;h2&gt;
  
  
  Basic commands for working with text:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt; Ctrl + A =&amp;gt; move cursor in the front of text&lt;/li&gt;
&lt;li&gt; Ctrl + E =&amp;gt; move cursor in the end of text&lt;/li&gt;
&lt;li&gt; Ctrl + U =&amp;gt; remove(crop) the word from cursor till start of the word&lt;/li&gt;
&lt;li&gt; Ctrl + K =&amp;gt; remove(crop) the word from cursor till end of word&lt;/li&gt;
&lt;li&gt; Ctrl + Y =&amp;gt; Paste cropped text&lt;/li&gt;
&lt;li&gt; Ctrl + Shift + C =&amp;gt; Copy text to clipboard&lt;/li&gt;
&lt;li&gt; Ctrl + Shift + P =&amp;gt; Paste text to clipboard&lt;/li&gt;
&lt;li&gt; Ctrl + C or Ctrl + Z =&amp;gt; Stop running the command&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Commands for files and folder:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt; ~ : Represents users home directory. 
&lt;code&gt;
 cd ~ or cd  =&amp;gt; return to users home directory.
&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; pwd =&amp;gt; Represents your absolute path of current working directory.&lt;/li&gt;
&lt;li&gt; .  =&amp;gt; Represents current directory.&lt;/li&gt;
&lt;li&gt; cd =&amp;gt; Change directory&lt;/li&gt;
&lt;li&gt; cd .. =&amp;gt; Moves one directory backwards&lt;/li&gt;
&lt;li&gt; cd ../../ =&amp;gt; Moves two directory backwards&lt;/li&gt;
&lt;li&gt; mkdir dir-name =&amp;gt; Create new directory if does not exist.&lt;/li&gt;
&lt;li&gt; rmdir dir-name =&amp;gt; Removes directory if exists&lt;/li&gt;
&lt;li&gt; cp file1 file2 =&amp;gt; Copies content of file1 to file2&lt;/li&gt;
&lt;li&gt; mv ./file1 ../ =&amp;gt; Move file1 from current directory to backward directory&lt;/li&gt;
&lt;li&gt; rm file1.txt =&amp;gt; Remove file1.txt&lt;/li&gt;
&lt;li&gt; rm -r dummy  =&amp;gt; Removes recursively all files and directory from dummy directory&lt;/li&gt;
&lt;li&gt; ls =&amp;gt; List all files and directories within your current working directory.&lt;/li&gt;
&lt;li&gt; touch file-name =&amp;gt; Will create a file with provided file-name.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Commands for changing file/directory permissions:
&lt;/h2&gt;

&lt;p&gt;when you run &lt;code&gt;ls -la&lt;/code&gt; on terminal you might see below:&lt;/p&gt;

&lt;p&gt;drwxrwxrwx : d =&amp;gt; directory, r =&amp;gt; read, w =&amp;gt; write, x =&amp;gt; excute, - &lt;br&gt;
   =&amp;gt; no permission.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if d is blank then, its a file (-rwxr-xr-x)
first group(drwx) - represents owner( who created the file)
second(rwx) - represents user group (user groups other than owner, who has access to file)
third(rwx) - represents others
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;code&gt;Numerical value for permissions r, w ,x:&lt;br&gt;
    r - 4&lt;br&gt;
    w - 2&lt;br&gt;
    x - 1&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;chmod XXX : this is used to change the permission associated with file/directory. It's called change mode. &lt;br&gt;
X denotes permission number for an group(owner, user-group, other).&lt;br&gt;
&lt;code&gt;chmod 644 - will assign read write to owner and read to both user group and other group.&lt;br&gt;
The default permission is 644.&lt;br&gt;
permission 777 - means all users(owner, user, others) have got full permission(rwx) on file/directory.&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;chown user fileName: change ownership of a file or directory&lt;br&gt;
&lt;code&gt;chown user:group filename&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Commands to create hard and soft links for file:
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Link =&amp;gt; A link in UNIX are pointers pointing to a file or a directory. Links allow more than one file name to refer to the same file, elsewhere.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Two ways to create symlinks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; ln -s file1 file 2 =&amp;gt; This will create a soft link file2 for referring file1.
Soft links break if the source file(file1) is moved or moved.&lt;/li&gt;
&lt;li&gt; ln file 1 file 2 =&amp;gt; This will create a hard link file2 for referring file1.
Hard links work even if then source(file1) is moved.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Commands for searching/displaying text:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;grep -n “the” file1.txt =&amp;gt; searches "the" in file1.txt with numbered line.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;cat file1.txt =&amp;gt; Displays the content of file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;| =&amp;gt; Pipe is used to send the result of one command to next command after pipe to execute on it.&lt;br&gt;
&lt;code&gt;cat file.txt | wc : here result of cat command is send to wc command for further processing.&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;head filename =&amp;gt; Display first 10 lines of a file.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;head file1.txt =&amp;gt; Displays first 10 lines of file1.txt&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;head -n5 file1.txt =&amp;gt; Displays first 5 lines of file1.txt&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;tail filename =&amp;gt; Display last 10 lines of a file.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;tail file1.txt =&amp;gt; Displays last 10 lines of file1.txt&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;tail -n5 file1.txt =&amp;gt; Displays last 5 lines of file1.txt&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cat file1.txt | tail -n5 | cat -n =&amp;gt; This displays the last 5 lines of the file1.txt numbered as 1, 2, 3, 4, 5.&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;less filename =&amp;gt; Less will open the entire file but displays the part of file in scrollable mode, user can navigate in the file. Displays the content of file page by page. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Redirection of Inputs/Outputs/Stderr:
&lt;/h2&gt;

&lt;p&gt;### File Descriptor and their representations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; stdin  =&amp;gt;  0  =&amp;gt; Input from the console&lt;/li&gt;
&lt;li&gt; stdout =&amp;gt;  1  =&amp;gt; Output to console&lt;/li&gt;
&lt;li&gt; stderr =&amp;gt;  2  =&amp;gt; Error to console&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;### Redirection:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; ' &amp;gt; ' =&amp;gt; output of command1 is redirected to file.txt/stdout (Output Redirection).&lt;/li&gt;
&lt;li&gt; ' &amp;gt;&amp;gt; ' =&amp;gt; output of command1 is appended to file.txt/stdout (Output Redirection).&lt;/li&gt;
&lt;li&gt; ' &amp;lt; ' =&amp;gt; command 1 reads its input from file.txt/stdin (Input Redirection).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  RAM CPU and Disk Info:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt; free -h =&amp;gt; Displays available and used RAM(memory).&lt;/li&gt;
&lt;li&gt; cat /proc/cpuinfo =&amp;gt; Displays information about cpu like cores etc.&lt;/li&gt;
&lt;li&gt; df -h =&amp;gt; Displays information about available and used Disks.
-h here is used to display the information in human readable format&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Other useful Command:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt; man option command =&amp;gt; Displays manual page for a command.&lt;/li&gt;
&lt;li&gt; help command =&amp;gt; Display help information related to a command.&lt;/li&gt;
&lt;li&gt; uname -a =&amp;gt; Displays information about linux system on your machine.&lt;/li&gt;
&lt;li&gt; hostname =&amp;gt; Display the hostname and ip for your machine in the network.
&lt;code&gt;
hostname -I =&amp;gt; Will Display the ip of your system in network.&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; ping =&amp;gt; To test the reachability of the system in network.
&lt;code&gt;
ping google.com =&amp;gt; Will ping to google.com and if that 
available in network it will return the data packets&lt;/code&gt; &lt;/li&gt;
&lt;/ul&gt;

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