<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Viraj's Blog]]></title><description><![CDATA[Viraj's Blog]]></description><link>https://viraj-verse.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Tue, 15 Sep 2026 06:35:12 GMT</lastBuildDate><atom:link href="https://viraj-verse.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Linux Shell Scripting : Functions &Cases]]></title><description><![CDATA[These were the topics that are covered during this session.
Functions

Functions refer to blocks of code that can be defined and executed within scripts or the command line.

These functions allow you to modularize your code, making it easier to mana...]]></description><link>https://viraj-verse.hashnode.dev/linux-shell-scripting-functions-cases</link><guid isPermaLink="true">https://viraj-verse.hashnode.dev/linux-shell-scripting-functions-cases</guid><category><![CDATA[Linux]]></category><category><![CDATA[#learnwithpra9]]></category><category><![CDATA[linux for beginners]]></category><category><![CDATA[linux kernel]]></category><category><![CDATA[Programming Blogs]]></category><dc:creator><![CDATA[Viraj Nalbalwar]]></dc:creator><pubDate>Sun, 06 Aug 2023 09:21:15 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1691313479064/45d152c3-287d-44cc-a54c-552bbf9e29ca.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>These were the topics that are covered during this session.</p>
<h3 id="heading-functions"><strong>Functions</strong></h3>
<ul>
<li><p>Functions refer to <strong>blocks of code</strong> that can be <strong>defined</strong> and <strong>executed</strong> within <strong>scripts</strong> or the <strong>command line.</strong></p>
</li>
<li><p>These functions allow you to <strong>modularize</strong> your <strong>code</strong>, making it <strong>easier to manage</strong>, <strong>reuse</strong>, and <strong>understand</strong>.</p>
</li>
<li><p>Functions can <strong>accept parameters</strong> and <strong>return</strong> values, just like in programming languages.</p>
</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
<span class="hljs-function"><span class="hljs-title">Function_Name</span></span> () {
    <span class="hljs-comment">#Statements</span>
}
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment">#Example:</span>
<span class="hljs-comment">#A function to print "Hello Linux" on terminal</span>

<span class="hljs-comment">#!/bin/bash</span>
<span class="hljs-comment">#Function Defination</span>
<span class="hljs-function"><span class="hljs-title">print_Hello</span></span> () {
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"Hello Linux"</span>
}    

<span class="hljs-comment">#Function Call</span>
print_Hello
</code></pre>
<hr />
<p><strong>Function To Add Two Numbers</strong></p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>
<span class="hljs-comment">#Function Defn</span>
<span class="hljs-function"><span class="hljs-title">addTwoNumbers</span></span> () {
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"Enter the first number:"</span>
    <span class="hljs-built_in">read</span> num1

    <span class="hljs-built_in">echo</span> <span class="hljs-string">"Enter the second number:"</span>
    <span class="hljs-built_in">read</span> num2

    sum=$(expr <span class="hljs-variable">$num1</span> + <span class="hljs-variable">$num2</span>)
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"The addition of <span class="hljs-variable">${num1}</span> + <span class="hljs-variable">${num2}</span> is : <span class="hljs-variable">${sum}</span>"</span>
} 

<span class="hljs-comment">#Function Call</span>
addTwoNumbers

<span class="hljs-comment">#Output:</span>
Enter the first number:
10
Enter the second number:
20
The addition of 10 + 20 is : 30
</code></pre>
<hr />
<h3 id="heading-case"><strong>Case</strong></h3>
<ul>
<li><p>In <strong>Linux Shell Scripting</strong>, "<strong>cases</strong>" refer to <strong>switch/case</strong> statements.</p>
</li>
<li><p>These are <strong>control structures</strong> that allow you to perform different actions based on the value of a <strong>variable</strong> or <strong>expression</strong>.</p>
</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
<span class="hljs-keyword">case</span> <span class="hljs-variable">${variable}</span> <span class="hljs-keyword">in</span>
val1)
    <span class="hljs-comment">#Statement1</span>
;;
val2)
    <span class="hljs-comment">#Statement2</span>
;;
*)
    <span class="hljs-comment">#Default Statement</span>
;;
<span class="hljs-keyword">esac</span>
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment">#Example:</span>
<span class="hljs-comment">#Write a case which when executes, perform some commands in Linux</span>

<span class="hljs-comment">#!/bin/bash</span>
<span class="hljs-built_in">echo</span> <span class="hljs-string">"1 : File Create"</span>
<span class="hljs-built_in">echo</span> <span class="hljs-string">"2 : Display IP Address"</span>
<span class="hljs-built_in">echo</span> <span class="hljs-string">"3 : Current Directory"</span>
<span class="hljs-built_in">echo</span> <span class="hljs-string">"4 : Make Directory"</span>

<span class="hljs-built_in">echo</span> <span class="hljs-string">"Enter the input : "</span>
<span class="hljs-built_in">read</span> input

<span class="hljs-keyword">case</span> <span class="hljs-variable">${input}</span> <span class="hljs-keyword">in</span>
1)
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"Enter the file name : "</span>
    <span class="hljs-built_in">read</span> fileName
    touch /tmp/<span class="hljs-variable">${filename}</span>
;;
2)
    ifconfig
;;
3)
    <span class="hljs-built_in">pwd</span>
;;
4)
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"Enter the directory name : "</span>
    <span class="hljs-built_in">read</span> dirName
    mkdir /tmp/<span class="hljs-variable">${dirname}</span>
;;
*)
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"I can't do it !!"</span>
;;
<span class="hljs-keyword">esac</span>

<span class="hljs-comment">#Executing the Script...</span>
1 : File Create
2 : Display IP Address
3 : Current Directory
4 : Make Directory
Enter the input :
3
/home/viraj
</code></pre>
<hr />
<p>This was our last lecture at the <strong>Linux Workshop</strong>. <a class="user-mention" href="https://hashnode.com/@AutomateMaster">Pranav Jambare</a> (<strong>DevOps @TCS</strong>), delivered an exceptional amount of lectures. His guidance led us through intricate Linux landscapes, <strong>mastering commands</strong> and <strong>scripting</strong>. His <strong>passion</strong> and <strong>support</strong> created a vibrant learning environment, igniting our love for Linux.</p>
<p><strong>A big thank you to Pranav Sir for an amazing workshop.</strong></p>
<hr />
]]></content:encoded></item><item><title><![CDATA[Shell Scripting - Loops & Command Line Arguments]]></title><description><![CDATA[These topics are covered in today's session by Pranav Jambare
Loops in Linux

Loops in shell scripting allow you to execute a series of commands repeatedly, based on a condition or a list of items.

Types of Loops
While Loop

The while loop repeatedl...]]></description><link>https://viraj-verse.hashnode.dev/shell-scripting-loops-command-line-arguments</link><guid isPermaLink="true">https://viraj-verse.hashnode.dev/shell-scripting-loops-command-line-arguments</guid><category><![CDATA[Linux]]></category><category><![CDATA[linux for beginners]]></category><category><![CDATA[linux-commands]]></category><category><![CDATA[#learnwithpra9]]></category><category><![CDATA[linux-basics]]></category><dc:creator><![CDATA[Viraj Nalbalwar]]></dc:creator><pubDate>Tue, 25 Jul 2023 16:59:02 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1690304075695/efefa9f4-87e4-48ce-8bf9-556b5ad9c798.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>These topics are covered in today's session by <a class="user-mention" href="https://hashnode.com/@AutomateMaster">Pranav Jambare</a></p>
<h3 id="heading-loops-in-linux"><strong>Loops in Linux</strong></h3>
<ul>
<li>Loops in shell scripting allow you to <strong>execute a series of commands</strong> repeatedly, based on a <strong>condition</strong> or a <strong>list of items</strong>.</li>
</ul>
<h3 id="heading-types-of-loops"><strong>Types of Loops</strong></h3>
<p><strong>While Loop</strong></p>
<ul>
<li><p>The while loop repeatedly executes the commands inside the loop as long as the condition <strong>remains true</strong>.</p>
</li>
<li><p>If the condition <strong>becomes false</strong>, the loop <strong>stops executing</strong> and moves to the next part of the script.</p>
</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
<span class="hljs-keyword">while</span> &lt;<span class="hljs-built_in">command</span>&gt;;
<span class="hljs-keyword">do</span>
    <span class="hljs-comment"># Statement execute if command is true</span>
<span class="hljs-keyword">done</span>
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment">#Example: (Create a sample.sh and edit the file with the given script)</span>
<span class="hljs-comment">#Printing numbers from 1 to 20</span>
<span class="hljs-comment">#!/bin/bash</span>
A=1
<span class="hljs-keyword">while</span> [ <span class="hljs-variable">${A}</span> -le 20 ];
<span class="hljs-keyword">do</span>
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"A = <span class="hljs-variable">${A}</span>"</span>
    A=`expr <span class="hljs-variable">${A}</span> + 1` 
<span class="hljs-keyword">done</span>

<span class="hljs-comment">#After running script...</span>
A = 1
A = 2
...
A = 19
A = 20
</code></pre>
<hr />
<p><strong>Until Loop</strong></p>
<ul>
<li><p>The until loop is <strong>similar</strong> to the while loop, but it <strong>continues executing</strong> the commands inside the loop <strong>until</strong> the condition becomes <strong>false</strong>.</p>
</li>
<li><p>Once the condition is <strong>true</strong>, the <strong>loop stops executing</strong>.</p>
</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
until &lt;<span class="hljs-built_in">command</span>&gt;;
<span class="hljs-keyword">do</span>
    <span class="hljs-comment"># Statement execute if command is false</span>
<span class="hljs-keyword">done</span>
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment">#Example: (Create a sample.sh and edit the file with the given script)</span>
<span class="hljs-comment">#Printing numbers from 20 to 1</span>
<span class="hljs-comment">#!/bin/bash</span>
A=20
<span class="hljs-keyword">while</span> [ <span class="hljs-variable">${A}</span> -ge 1 ];
<span class="hljs-keyword">do</span>
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"A = <span class="hljs-variable">${A}</span>"</span>
    A=`expr <span class="hljs-variable">${A}</span> - 1` 
<span class="hljs-keyword">done</span>

<span class="hljs-comment">#After running script...</span>
A = 20
A = 19
...
A = 2
A = 1
</code></pre>
<hr />
<p><strong>For Loop</strong></p>
<ul>
<li><p>The for loop <strong>iterates</strong> over <strong>each item</strong> in the list, and the <strong>variable</strong> takes the <strong>value</strong> of each item in each iteration.</p>
</li>
<li><p>The commands inside the loop are executed for <strong>each item in the list</strong>.</p>
</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
<span class="hljs-keyword">for</span> var <span class="hljs-keyword">in</span> word1 word2 .. wordn;
<span class="hljs-keyword">do</span>
    <span class="hljs-comment"># Statement executed till element end</span>
<span class="hljs-keyword">done</span>
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment">#Example:</span>
<span class="hljs-comment">#Printing the names of students...</span>
<span class="hljs-comment">#!/bin/bash</span>
A=1
<span class="hljs-keyword">for</span> studName <span class="hljs-keyword">in</span> Viraj Amogh Suyash;
<span class="hljs-keyword">do</span>
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"The name of student <span class="hljs-variable">${A}</span> is : <span class="hljs-variable">${studName}</span>"</span>
    A=`expr <span class="hljs-variable">${A}</span> + 1`
<span class="hljs-keyword">done</span>

<span class="hljs-comment">#After running the script...</span>
The name of student 1 is : Viraj
The name of student 2 is : Amogh
The name of student 3 is : Suyash
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment">#Example:</span>
<span class="hljs-comment">#To print alphabets from A to Z</span>
<span class="hljs-comment">#!/bin/bash</span>
<span class="hljs-keyword">for</span> alpha <span class="hljs-keyword">in</span> {A..Z};
<span class="hljs-keyword">do</span>
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"<span class="hljs-variable">${alpha}</span>"</span>
<span class="hljs-keyword">done</span>

<span class="hljs-comment">#After running the script...</span>
A
B...
..
Y
Z
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment">#Example:</span>
<span class="hljs-comment">#To print the names of students from a file</span>
<span class="hljs-comment">#!/bin/bash</span>
<span class="hljs-keyword">for</span> name <span class="hljs-keyword">in</span> $(cat /home/viraj/namesFile);
<span class="hljs-keyword">do</span>
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"The name is : <span class="hljs-variable">${name}</span>"</span>
<span class="hljs-keyword">done</span>
</code></pre>
<hr />
<h3 id="heading-command-line-arguments"><strong>Command Line Arguments</strong></h3>
<ul>
<li><p>Command Line Arguments are <strong>inputs</strong> or <strong>parameters</strong> provided to a <strong>command</strong> or <strong>script</strong> when it is <strong>executed</strong> in the terminal.</p>
</li>
<li><p>$1 $2 $3 --&gt; The <strong>first</strong> command-line argument is represented by <strong>$1</strong>, the <strong>second</strong> one by <strong>$2</strong>, and so on.</p>
</li>
<li><p>$0 --&gt; Represents the <strong>name</strong> of the <strong>script</strong> itself.</p>
</li>
<li><p>$@ --&gt; Passing arguments one-by-one</p>
</li>
<li><p>$# --&gt; <strong>Total number</strong> of command line arguments provided</p>
</li>
<li><p>$* --&gt; Represents all the command-line arguments as a <strong>single string</strong></p>
</li>
<li><p>$$ --&gt; Represents the process ID (<strong>PID</strong>) of the currently running <strong>shell</strong> or <strong>script</strong></p>
</li>
<li><p>$? --&gt; Holds the status of the last executed command</p>
</li>
<li><p>$! --&gt; Hold the process ID (<strong>PID</strong>) of the last executed command</p>
</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#Example:</span>
<span class="hljs-comment">#!/bin/bash</span>
<span class="hljs-keyword">for</span> names <span class="hljs-keyword">in</span> <span class="hljs-variable">$1</span> <span class="hljs-variable">$2</span>;
<span class="hljs-keyword">do</span>
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"Your name is : <span class="hljs-variable">${names}</span>"</span>
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"The name of script is : <span class="hljs-variable">$0</span>"</span>
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"Passing args one-by-one : <span class="hljs-variable">$@</span>"</span>
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"Total number of args provided : <span class="hljs-variable">$#</span>"</span>
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"Args as a single string : $*"</span>
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"PID of current script : $$"</span>
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"Status of last executed cmd: $?"</span>
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"PID of last executed cmd: $!"</span>
<span class="hljs-keyword">done</span>

<span class="hljs-comment">#After running script...</span>
Your name is : Viraj
The name of script is : sampleFile.sh
Passing args one-by-one : Viraj Amogh
Total number of args provided : 2
Args as a single string : Viraj Amogh
PID of current script : 4920
Status of last executed cmd : 0
PID of last executed cmd : --

Your name is : Amogh
The name of script is : sampleFile.sh
Passing args one-by-one : Viraj Amogh
Total number of args provided : 2
Args as a single string : Viraj Amogh
PID of current script : 4920
Status of last executed cmd : 0
PID of last executed cmd : --
</code></pre>
<hr />
<h3 id="heading-shell-scripting-question"><strong>Shell Scripting Question</strong></h3>
<p><strong>Q.</strong> Create 5 directories and take user input to read name of those directories. Now create two files in each directory and take user input to name those files. Now take user input to add some content in each file.</p>
<pre><code class="lang-bash"><span class="hljs-comment">#Answer:</span>
<span class="hljs-comment">#!/bin/bash</span>
<span class="hljs-keyword">for</span> dirName <span class="hljs-keyword">in</span> {1..5};
<span class="hljs-keyword">do</span> 
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"Enter the name of directory : "</span>
    <span class="hljs-built_in">read</span> dir
    mkdir <span class="hljs-variable">${dir}</span>

    <span class="hljs-keyword">for</span> fileName <span class="hljs-keyword">in</span> 1 2;
    <span class="hljs-keyword">do</span> 
        <span class="hljs-built_in">echo</span> <span class="hljs-string">"Enter the name of file : "</span>
        <span class="hljs-built_in">read</span> file

        touch /home/viraj/<span class="hljs-variable">${dir}</span>/<span class="hljs-variable">${file}</span>

        <span class="hljs-built_in">echo</span> <span class="hljs-string">"Enter the content for file : "</span>
        <span class="hljs-built_in">read</span> content &gt;&gt; /home/viraj/<span class="hljs-variable">${dir}</span>/<span class="hljs-variable">${file}</span>
    <span class="hljs-keyword">done</span>
<span class="hljs-keyword">done</span>
</code></pre>
<hr />
]]></content:encoded></item><item><title><![CDATA[Filters & Shell Script In Linux]]></title><description><![CDATA[These topics are covered in today's session by Pranav Jambare
Filters

In Linux, filters refer to commands that process input data and produce output data based on specific criteria.

Used, when we want to see exact data rather than the whole data.

...]]></description><link>https://viraj-verse.hashnode.dev/filters-shell-script-in-linux</link><guid isPermaLink="true">https://viraj-verse.hashnode.dev/filters-shell-script-in-linux</guid><category><![CDATA[Linux]]></category><category><![CDATA[linux-basics]]></category><category><![CDATA[linux kernel]]></category><category><![CDATA[#learnwithpra9]]></category><category><![CDATA[linux for beginners]]></category><dc:creator><![CDATA[Viraj Nalbalwar]]></dc:creator><pubDate>Mon, 24 Jul 2023 18:46:18 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1690224302237/e3681f60-8e1b-4cf7-a33c-884ec24c68d7.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>These topics are covered in today's session by <a class="user-mention" href="https://hashnode.com/@AutomateMaster">Pranav Jambare</a></p>
<h3 id="heading-filters"><strong>Filters</strong></h3>
<ul>
<li><p>In Linux, filters refer to <strong>commands</strong> that process <strong>input data</strong> and <strong>produce output</strong> <strong>data</strong> based on <strong>specific criteria</strong>.</p>
</li>
<li><p>Used, when we want to see exact data rather than the whole data.</p>
</li>
<li><p>Some of the common filters will be explained below.</p>
</li>
</ul>
<hr />
<h3 id="heading-sort"><strong>Sort</strong></h3>
<ul>
<li>This sort filter is used to <strong>sort</strong> the content of a file based on the <strong>specific format</strong> given for sorting.</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#To sort the content of file in ascending order</span>
<span class="hljs-comment">#Also display the output on the terminal</span>

<span class="hljs-comment">#Syntax:</span>
sort &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
[viraj@localhost ~]$ vim sortTheFile
apple
mango
banana
grapes
jackfruit
pineapple

[viraj@localhost ~]$ sort sortTheFile
apple
banana
grapes
jackfruit
mango
pineapple
</code></pre>
<p><strong>Options for the sort filter</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>

<span class="hljs-comment"># Used to sort the content of file in decending order</span>
sort -r &lt;filename&gt;

<span class="hljs-comment"># Used to sort the numbers present in the file in ascending order</span>
sort -n &lt;filename&gt;

<span class="hljs-comment"># Used to check whether the file content is sorted or not</span>
sort -c &lt;filename&gt;

<span class="hljs-comment"># Used to sort the content of file &amp; also remove the duplicate content in file</span>
sort -u &lt;filename&gt;

<span class="hljs-comment">#used to sort the months in order</span>
sort -M &lt;filename&gt;
</code></pre>
<hr />
<h3 id="heading-tail"><strong>Tail</strong></h3>
<ul>
<li>The tail filter is used to display the last few lines of a file or stream of data.</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
tail &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
[viraj@localhost ~]$ tail mySampleFile
This is a sample file
_____________________________________________________________________________

<span class="hljs-comment"># tail filter with options: </span>
<span class="hljs-comment">#To display the last 'n' lines of a file</span>
<span class="hljs-comment">#Syntax:</span>
tail -n &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
[viraj@localhost ~]$ vim filterFile
Hello
Welcome
To
My
Blog

[viraj@localhost ~]$ tail -3 filterFile
To
My
Blog
_____________________________________________________________________________

<span class="hljs-comment"># To merge the content of the files</span>
<span class="hljs-comment">#Syntax:</span>
tail -q &lt;file1&gt; &lt;file2&gt;

<span class="hljs-comment">#Example:</span>
<span class="hljs-comment">#Creating the file1 and file2 and then merging them...</span>
[viraj@localhost ~]$ vim file1
This is my file1 created by me

[viraj@localhost ~]$ vim file2
This is another file2 created by me again!!

[viraj@localhost ~]$ tail -q file1 file2
This is my file1 created by me
This is another file2 created by me again!!
_____________________________________________________________________________

<span class="hljs-comment"># To get the dynamic (real-time) output on the terminal</span>
<span class="hljs-comment">#Syntax:</span>
tail -f &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
<span class="hljs-comment"># To get the logs output dynamically in myCustom.log file</span>
tail -f myCustom.log
</code></pre>
<hr />
<h3 id="heading-head"><strong>Head</strong></h3>
<ul>
<li><p>The head filter is used to display the <strong>first few lines</strong> of a file or a <strong>stream of data</strong>.</p>
</li>
<li><p>It is the <strong>counterpart</strong> to the <strong>tail command</strong>, which shows the <strong>last few lines</strong> of a file.</p>
</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#To display first 'n' lines of the file</span>
<span class="hljs-comment">#Syntax:</span>
head -n &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
<span class="hljs-comment">#Creating the file...</span>
[viraj@localhost ~]$ vim myHeadFile
Hello 
Again
Nice 
Meeting
You!!

<span class="hljs-comment">#First 2 lines are printed...</span>
[viraj@localhost ~]$ head -2 myHeadFile
Hello 
Again

<span class="hljs-comment">#The other head options are very similar to the tail options mentioned above...</span>
</code></pre>
<hr />
<h3 id="heading-wc"><strong>WC</strong></h3>
<ul>
<li><strong>WC</strong> is a <strong>filter</strong> that stands for <strong>word count</strong>.</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
wc &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
[viraj@localhost ~]$ wc myFile
1 8 37 myFile
____________________________________________________________________________

<span class="hljs-comment"># wc with options:</span>
<span class="hljs-comment">#To get the line count in the file</span>
<span class="hljs-comment">#Syntax:</span>
wc -l &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
[viraj@localhost ~]$ wc -l myFile
1 myFile
____________________________________________________________________________

<span class="hljs-comment"># To get the count of characters in the file</span>
<span class="hljs-comment">#Syntax:</span>
wc -m &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
[viraj@localhost ~]$ wc -m myFile
37 myFile
____________________________________________________________________________

<span class="hljs-comment"># To get the count of bytes in the file</span>
<span class="hljs-comment">#Syntax:</span>
wc -c &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
[viraj@localhost ~]$ wc -c myFile
37 myFile
____________________________________________________________________________

<span class="hljs-comment"># To get the count of words in the file</span>
<span class="hljs-comment"># Syntax:</span>
wc -w &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
[viraj@localhost ~]$ wc -w myFile
8 myFile
</code></pre>
<hr />
<h3 id="heading-uniq"><strong>Uniq</strong></h3>
<ul>
<li><p>The <strong>uniq</strong> filter in Linux is used to <strong>remove duplicate</strong> <strong>lines</strong> from a <strong>sorted file</strong> or <strong>input stream</strong>.</p>
</li>
<li><p>Its primary purpose is to <strong>identify</strong> and <strong>display unique lines</strong>, removing <strong>consecutive duplicates</strong> and leaving only <strong>one occurrence</strong> of each unique line.</p>
</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#To get count of repetition</span>
<span class="hljs-comment">#Syntax:</span>
uniq -c &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
<span class="hljs-comment"># Creating a file...</span>
[viraj@localhost ~]$ vim myUniqFile
viraj
viraj
amogh
suyash
suyash

[viraj@localhost ~]$ uniq -c myUniqFile
2 viraj
1 amogh
2 suyash
____________________________________________________________________________

<span class="hljs-comment">#To only print the repeated lines</span>
<span class="hljs-comment">#Syntax:</span>
uniq -d &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
[viraj@localhost ~]$ uniq -d myUniqFile
viraj
suyash
____________________________________________________________________________

<span class="hljs-comment">#To print repeated lines with occurence</span>
<span class="hljs-comment">#Syntax:</span>
uniq -D &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
[viraj@localhost ~]$ uniq -D myUniqFile
viraj 
viraj
suyash
suyash
____________________________________________________________________________

<span class="hljs-comment">#To only print unique lines</span>
<span class="hljs-comment">#Syntax:</span>
uniq -u &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
[viraj@localhost ~]$ uniq -u myUniqFile
amogh
</code></pre>
<hr />
<h3 id="heading-comm"><strong>Comm</strong></h3>
<pre><code class="lang-bash"><span class="hljs-comment">#To show the common content between the two files</span>
<span class="hljs-comment">#Syntax:</span>
comm &lt;file1&gt; &lt;file2&gt;

<span class="hljs-comment">#Example:</span>
<span class="hljs-comment">#Creating two files...</span>
[viraj@localhost ~]$ vim commFile1 
ABC
DEF
GHI
JKL

[viraj@localhost ~]$ vim commFile2
ABC
DEF
GHO
JKM

[viraj@localhost ~]$ comm myFile1 myFile2
            ABC
            DEF
GHI                  
      GHO
JKL   
      JKM
</code></pre>
<hr />
<h3 id="heading-diff"><strong>Diff</strong></h3>
<pre><code class="lang-bash"><span class="hljs-comment">#To show the different content between the two files</span>
<span class="hljs-comment">#Syntax:</span>
diff &lt;file1&gt; &lt;file2&gt;

<span class="hljs-comment">#Example:</span>
[viraj@localhost ~]$ diff myFile1 myFile2
3,4c3,4
&lt; GHI
&lt; JKL
------
&gt; GHO
&gt; JKM
</code></pre>
<hr />
<h3 id="heading-grep"><strong>GREP</strong></h3>
<pre><code class="lang-bash"><span class="hljs-comment"># To search the exact word</span>
<span class="hljs-comment">#Syntax:</span>
grep -w &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
[viraj@localhost ~]$ grep computer myFile
____________________________________________________________________________

<span class="hljs-comment"># To search the word with case insensitivity</span>
<span class="hljs-comment">#Syntax:</span>
grep -i -w &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
[viraj@localhost ~]$ grep -i computer myFile
____________________________________________________________________________

<span class="hljs-comment"># To display only the matched words (whole words)</span>
<span class="hljs-comment">#Syntax:</span>
grep -o -w &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
[viraj@localhost ~]$ grep -o computer myFile
____________________________________________________________________________

<span class="hljs-comment"># To get count of a word in a file</span>
<span class="hljs-comment">#Syntax:</span>
grep -c -w &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
[viraj@localhost ~]$ grep -c computer myFile
____________________________________________________________________________

<span class="hljs-comment"># To search for multiple words</span>
<span class="hljs-comment">#Syntax:</span>
grep -e -w -e -w &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
[viraj@localhost ~]$ grep -e computer -e program myFile
____________________________________________________________________________

<span class="hljs-comment"># To display the matched line and line number</span>
<span class="hljs-comment">#Syntax:</span>
grep -n -w &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
[viraj@localhost ~]$ grep -n computer myFile
</code></pre>
<hr />
<h3 id="heading-awk"><strong>AWK</strong></h3>
<pre><code class="lang-bash"><span class="hljs-comment"># To print the content of the file</span>
<span class="hljs-comment">#Syntax:</span>
awk <span class="hljs-string">'{print}'</span> &lt;fileName&gt;

<span class="hljs-comment">#Example:</span>
[viraj@localhost ~]$ awk <span class="hljs-string">'{print}'</span> myFile
____________________________________________________________________________

<span class="hljs-comment"># To print the lines that match the given word in the file</span>
<span class="hljs-comment">#Syntax:</span>
awk <span class="hljs-string">'/word/ {print}'</span> &lt;fileName&gt;

<span class="hljs-comment">#Example:</span>
[viraj@localhost ~]$ awk <span class="hljs-string">'/computer/ {print}'</span> myFile
____________________________________________________________________________

<span class="hljs-comment"># To print specific words of each line in the file</span>
<span class="hljs-comment">#Syntax:</span>
awk <span class="hljs-string">'{print $&lt;lineNumber&gt;, $&lt;lineNumber&gt;}'</span> &lt;fileName&gt;

<span class="hljs-comment">#Example:</span>
[viraj@localhost ~]$ awk <span class="hljs-string">'{print $2, $6}'</span> myFile
____________________________________________________________________________

<span class="hljs-comment"># To print the last word of each line in the file</span>
<span class="hljs-comment">#Syntax:</span>
awk <span class="hljs-string">'{print $NF}'</span> &lt;fileName&gt;

<span class="hljs-comment">#Example:</span>
[viraj@localhost ~]$ awk <span class="hljs-string">'{print $NF}'</span> myFile
____________________________________________________________________________

<span class="hljs-comment"># To print specific words of specific lines in the file</span>
<span class="hljs-comment">#Syntax:</span>
awk <span class="hljs-string">'NR==&lt;line_number&gt; {print $&lt;lineNumber&gt;, $&lt;lineNumber&gt;}'</span> &lt;fileName&gt;

<span class="hljs-comment">#Example:</span>
[viraj@localhost ~]$ awk <span class="hljs-string">'NR==2, NR==3 {print $2, $4}'</span> myFile
</code></pre>
<hr />
<h3 id="heading-cut"><strong>Cut</strong></h3>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
cut -d&lt;delimiter&gt; -f&lt;fieldNumber&gt; &lt;fileName&gt;

<span class="hljs-comment">#Example:</span>
[viraj@localhost ~]$ cut -d<span class="hljs-string">"-"</span> -f3 myFile
</code></pre>
<hr />
<h3 id="heading-sed"><strong>Sed</strong></h3>
<pre><code class="lang-bash"><span class="hljs-comment">#To replace the word by occurrence</span>
<span class="hljs-comment">#Syntax:</span>
sed <span class="hljs-string">'s/&lt;wordNeedToReplace&gt;/&lt;replaceWith&gt;/&lt;occurrenceNum&gt;'</span> &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
sed <span class="hljs-string">'s/ABC/VIRAJ/2'</span> myFile
_____________________________________________________________________________

<span class="hljs-comment">#To replace the word globally</span>
<span class="hljs-comment">#Syntax:</span>
sed <span class="hljs-string">'s/&lt;wordNeedToReplace&gt;/&lt;replaceWith&gt;/g'</span> &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
sed <span class="hljs-string">'s/ABC/VIRAJ/g'</span> myFile
_____________________________________________________________________________

<span class="hljs-comment">#To replace the word on the specific line</span>
<span class="hljs-comment">#Syntax:</span>
sed <span class="hljs-string">'&lt;lineNumber&gt; s/&lt;wordNeedToReplace&gt;/&lt;replaceWith&gt;/'</span> &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
sed <span class="hljs-string">'3 s/program/programs/'</span> myFile
_____________________________________________________________________________

<span class="hljs-comment">#To delete the last line</span>
<span class="hljs-comment">#Syntax:</span>
sed <span class="hljs-string">'$d'</span> &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
sed <span class="hljs-string">'$d'</span> myFile
_____________________________________________________________________________

<span class="hljs-comment">#To delete particular lines</span>
<span class="hljs-comment">#Syntax:</span>
sed <span class="hljs-string">'&lt;lineNumber&gt;d'</span> &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
sed <span class="hljs-string">'1,3d'</span> myFile
_____________________________________________________________________________

<span class="hljs-comment">#To delete lines matching a word</span>
<span class="hljs-comment">#Syntax:</span>
sed <span class="hljs-string">'/word/d'</span> &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
sed <span class="hljs-string">'/computer/d'</span> myFile
</code></pre>
<hr />
<h3 id="heading-shell-script"><strong>Shell Script</strong></h3>
<ul>
<li><p>A shell script in Linux is a <strong>script</strong> written in a <strong>scripting language</strong> that is <strong>interpreted</strong> by a <strong>shell.</strong></p>
</li>
<li><p>A shell script is a <strong>series of commands</strong> written in a <strong>text file</strong> and <strong>executed</strong> as a <strong>single unit</strong>.</p>
</li>
<li><p>In a shell script, you can use the full range of commands and features available in the shell, including <strong>loops</strong>, <strong>conditionals</strong>, <strong>functions</strong>, <strong>variables</strong>, and <strong>input/output</strong> <strong>redirection</strong>.</p>
</li>
<li><p>Shell scripts allow you to <strong>automate</strong> tasks, <strong>execute multiple commands</strong> sequentially, and perform <strong>complex operations</strong> that would otherwise require manual execution on the command line.</p>
</li>
<li><p>The file extension commonly used for shell scripts is <strong>.sh</strong>, but it is <strong>not mandatory</strong>.</p>
</li>
</ul>
<hr />
<h3 id="heading-types-of-shell-script"><strong>Types of Shell Script</strong></h3>
<ol>
<li><p><strong>Non Interactive</strong> :</p>
<ul>
<li><p>Non-interactive shell scripts are designed to <strong>run without any user input</strong> during their execution.</p>
</li>
<li><p>They execute a <strong>predefined set of commands</strong> and <strong>do not require</strong> any interaction with the user while running.</p>
</li>
</ul>
</li>
<li><p><strong>Interactive</strong> :</p>
<ul>
<li><p>Interactive shell scripts are <strong>designed</strong> to <strong>interact</strong> with the user during their execution.</p>
</li>
<li><p>They <strong>prompt</strong> the user for <strong>input</strong> and <strong>respond</strong> accordingly.</p>
</li>
</ul>
</li>
<li><p><strong>Command Line</strong> :</p>
<ul>
<li>Command-line shell scripts are run from the command line and <strong>accept arguments</strong> provided by the <strong>user</strong> when <strong>executing the script.</strong></li>
</ul>
</li>
</ol>
<hr />
<h3 id="heading-shebang"><strong>Shebang</strong></h3>
<ul>
<li><p>The shebang, also known as a <strong>hashbang</strong> or <strong>pound-bang</strong>, is the special character sequence <strong>#!</strong> at the <strong>beginning</strong> of a <strong>script file</strong> in Linux.</p>
</li>
<li><p>The shebang indicates the <strong>interpreter</strong> that should be used to <strong>execute the script</strong>.</p>
</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-meta">#!/pathTo/interpreter</span>
</code></pre>
<ul>
<li>For example, in a <strong>Bash</strong> shell script, the <strong>shebang</strong> would typically be:</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>
</code></pre>
<hr />
<h3 id="heading-creating-and-running-a-script-in-linux"><strong>Creating and Running a Script in Linux</strong></h3>
<ul>
<li>Create a file with the extension <strong>.sh</strong></li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#Creating and editing the file in vim editor...</span>
vim Sample.sh
___________________________________________________________________________
<span class="hljs-comment">#At the beginning of the file use Shebang and start writing the script...</span>
<span class="hljs-comment">#Syntax:</span>
<span class="hljs-comment">#!/bin/bash</span>
&lt;setOfCommands&gt;...

<span class="hljs-comment">#Example:</span>
<span class="hljs-comment">#!/bin/bash</span>

<span class="hljs-built_in">echo</span> <span class="hljs-string">"This is my first script"</span>
<span class="hljs-built_in">echo</span> <span class="hljs-string">"Thank you!!"</span>

<span class="hljs-comment">#Now save the file...</span>
</code></pre>
<ul>
<li>Running the sample.sh script</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#You can give execute permission to user and then run the file</span>
<span class="hljs-comment">#Then run as shown...</span>
chmod 777 Sample.sh
./Sample.sh

<span class="hljs-comment">#Else, you can use bash command (if execute permission is missing)</span>
<span class="hljs-comment">#Then the file name to execute the file</span>
bash Sample.sh

<span class="hljs-comment">#Output:</span>
This is my first script 
Thank you!!
</code></pre>
<hr />
<h3 id="heading-to-declare-the-variables-in-linux-temporary"><strong>To declare the variables in Linux (Temporary)</strong></h3>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
&lt;variableName&gt;=&lt;value&gt;

<span class="hljs-comment">#Example:</span>
myName=Viraj

<span class="hljs-comment">#The above example shown has a temporary existance, i.e</span>
<span class="hljs-comment">#if bash command is execute the myName variable won't have it's existance and can't be used anymore</span>
<span class="hljs-comment">#To declare variables permanently use following method...</span>
</code></pre>
<hr />
<h3 id="heading-to-declare-the-variables-in-linux-permanent"><strong>To declare the variables in Linux (Permanent)</strong></h3>
<pre><code class="lang-bash"><span class="hljs-comment">#Open a file called bashrc or bash.bashrc (according to linux distro's) in vim editor</span>
<span class="hljs-comment">#Now, define the variables at the last</span>
<span class="hljs-comment">#Save the file</span>
<span class="hljs-comment">#Now try to use it in any of the commands, it would have its permanent existance</span>
<span class="hljs-built_in">echo</span> <span class="hljs-string">"Good Morning, <span class="hljs-variable">${myName}</span>"</span>
Good Morning, Viraj
</code></pre>
<hr />
<h3 id="heading-if-else-statements"><strong>If - Else Statements</strong></h3>
<ol>
<li><p><strong>Simple if</strong></p>
<pre><code class="lang-bash"> <span class="hljs-comment">#Syntax:</span>
 <span class="hljs-keyword">if</span> [ expression ]
 <span class="hljs-keyword">then</span>
     statement
 <span class="hljs-keyword">fi</span>
</code></pre>
<pre><code class="lang-bash"> <span class="hljs-comment">#Example:</span>
 <span class="hljs-keyword">if</span> [ <span class="hljs-variable">${A}</span> -gt <span class="hljs-variable">${B}</span> ]
 <span class="hljs-keyword">then</span>
     <span class="hljs-built_in">echo</span> <span class="hljs-string">"<span class="hljs-variable">${A}</span> is greater than <span class="hljs-variable">${B}</span>"</span>
 <span class="hljs-keyword">fi</span>
</code></pre>
</li>
<li><p><strong>If - Else</strong></p>
<pre><code class="lang-bash"> <span class="hljs-comment">#Syntax:</span>
 <span class="hljs-keyword">if</span> [ expression ]
 <span class="hljs-keyword">then</span>
     statement
 <span class="hljs-keyword">else</span>
     statement
 <span class="hljs-keyword">fi</span>
</code></pre>
<pre><code class="lang-bash"> <span class="hljs-comment">#Example:</span>
 <span class="hljs-keyword">if</span> [ <span class="hljs-variable">${A}</span> -gt <span class="hljs-variable">${B}</span> ]
 <span class="hljs-keyword">then</span>
     <span class="hljs-built_in">echo</span> <span class="hljs-string">"<span class="hljs-variable">${A}</span> is greater than <span class="hljs-variable">${B}</span>"</span>
 <span class="hljs-keyword">else</span>
     <span class="hljs-built_in">echo</span> <span class="hljs-string">"<span class="hljs-variable">${B}</span> is greater than <span class="hljs-variable">${A}</span>"</span>
 <span class="hljs-keyword">fi</span>
</code></pre>
</li>
<li><p><strong>Else-if Ladder</strong></p>
<pre><code class="lang-bash"> <span class="hljs-comment">#Syntax:</span>
 <span class="hljs-keyword">if</span> [ expression1 ]
 <span class="hljs-keyword">then</span>
     statement1

 <span class="hljs-keyword">elif</span> [ expression2 ]
 <span class="hljs-keyword">then</span>
     statement2

 <span class="hljs-keyword">else</span>
     statement5
 <span class="hljs-keyword">fi</span>
</code></pre>
<pre><code class="lang-bash"> <span class="hljs-comment">#Example:</span>
 <span class="hljs-keyword">if</span> [ <span class="hljs-variable">${age}</span> -lt 18 ]
 <span class="hljs-keyword">then</span>
     <span class="hljs-built_in">echo</span> <span class="hljs-string">"You are not allowed to drive!!"</span>
 <span class="hljs-keyword">elif</span> [ <span class="hljs-variable">${age}</span> -ge 18 ]
 <span class="hljs-keyword">then</span>
     <span class="hljs-built_in">echo</span> <span class="hljs-string">"You are allowed to drive!!"</span>
 <span class="hljs-keyword">elif</span> [ <span class="hljs-variable">${age}</span> -ge 100 ]
 <span class="hljs-keyword">then</span>
     <span class="hljs-built_in">echo</span> <span class="hljs-string">"Please don't drive!!"</span>
 <span class="hljs-keyword">else</span>
     <span class="hljs-built_in">echo</span> <span class="hljs-string">"Invalid Age!!"</span>
 <span class="hljs-keyword">fi</span>
</code></pre>
</li>
<li><p><strong>Nested If</strong></p>
<pre><code class="lang-bash"> <span class="hljs-comment">#Syntax:</span>
 <span class="hljs-keyword">if</span> [ expression1 ]
 <span class="hljs-keyword">then</span> 
     <span class="hljs-keyword">if</span> [ expression2 ]
     <span class="hljs-keyword">then</span>
         statement1
     <span class="hljs-keyword">else</span>
         statement2
     <span class="hljs-keyword">fi</span>
 <span class="hljs-keyword">else</span>
     statement3
 <span class="hljs-keyword">fi</span>
</code></pre>
<pre><code class="lang-bash"> <span class="hljs-comment">#Example:</span>
 <span class="hljs-keyword">if</span> [ <span class="hljs-variable">${firstName}</span> == Viraj ]
 <span class="hljs-keyword">then</span>
     <span class="hljs-built_in">echo</span> <span class="hljs-string">"First name verified!!"</span>
     <span class="hljs-keyword">if</span> [ <span class="hljs-variable">${lastName}</span> == Nalbalwar ]
         <span class="hljs-built_in">echo</span> <span class="hljs-string">"Verified User!!"</span>
     <span class="hljs-keyword">else</span>
         <span class="hljs-built_in">echo</span> <span class="hljs-string">"Last name incorrect!!"</span>
     <span class="hljs-keyword">fi</span>
 <span class="hljs-keyword">else</span>
     <span class="hljs-built_in">echo</span> <span class="hljs-string">"First name incorrect!!"</span>
 <span class="hljs-keyword">fi</span>
</code></pre>
</li>
</ol>
<hr />
]]></content:encoded></item><item><title><![CDATA[Booting Process, ACL, Processes, Process State, Alias in Linux]]></title><description><![CDATA[Booting Process

The booting process refers to the series of steps that take place when a computer starts up and loads the operating system into memory, it involves several stages and those are listed below.


Stages of the Booting Process

BIOS (Bas...]]></description><link>https://viraj-verse.hashnode.dev/booting-process-acl-processes-process-state-alias-in-linux</link><guid isPermaLink="true">https://viraj-verse.hashnode.dev/booting-process-acl-processes-process-state-alias-in-linux</guid><category><![CDATA[Linux]]></category><category><![CDATA[linux for beginners]]></category><category><![CDATA[#learnwithpra9]]></category><category><![CDATA[linux-commands]]></category><category><![CDATA[linux kernel]]></category><dc:creator><![CDATA[Viraj Nalbalwar]]></dc:creator><pubDate>Wed, 19 Jul 2023 18:31:07 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1689791450106/f4986ed7-d3a5-43b5-9573-42f5fbc0d4eb.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-booting-process"><strong>Booting Process</strong></h3>
<ul>
<li>The booting process refers to the series of <strong>steps</strong> that take place when a computer <strong>starts up</strong> and <strong>loads</strong> the operating system into <strong>memory</strong>, it involves several stages and those are listed below.</li>
</ul>
<hr />
<h3 id="heading-stages-of-the-booting-process"><strong>Stages of the Booting Process</strong></h3>
<ol>
<li><p><strong>BIOS</strong> (Basic Input Output System)</p>
<ul>
<li><p>When the computer is <strong>powered</strong> on, the <strong>BIOS</strong> is <strong>activated</strong>.</p>
</li>
<li><p>It performs the <strong>Power-On Self-Test</strong> (POST), <strong>detects</strong> and <strong>initializes</strong> essential hardware components, and <strong>locates</strong> the boot device (<em>usually the hard drive or SSD</em>) that contains the bootloader.</p>
</li>
</ul>
</li>
<li><p><strong>MBR</strong> (Master Boot Record)</p>
<ul>
<li><p>When the computer starts up, the BIOS <strong>executes</strong> the code in the <strong>MBR</strong>.</p>
</li>
<li><p>The structure of the MBR consists of <strong>three</strong> primary components:</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1689768763562/89d5725e-e88b-4a87-95cb-f6c550780799.png" alt class="image--center mx-auto" /></p>
<ol>
<li><p><strong>Bootloader</strong>: The MBR contains a small piece of <strong>executable code</strong> called the bootloader, which is responsible for <strong>locating</strong> and <strong>loading</strong> the main bootable partition.</p>
</li>
<li><p><strong>Partition Table</strong>: The MBR also contains a partition table that can hold <strong>information</strong> about up to <strong>four primary partitions</strong> on the storage device.</p>
</li>
<li><p><strong>Magic Number</strong> (<strong>Parity Bits</strong>): It acts as a simple form of <strong>data validation</strong> and if any part of the MBR is <strong>corrupted</strong> or <strong>altered</strong>, including the magic number, the BIOS will not consider it a <strong>valid</strong> bootable device.</p>
</li>
</ol>
</li>
</ul>
</li>
<li><p><strong>GRUB</strong> (GRand Unified Bootloader)</p>
<ul>
<li><p>GRUB is a popular <strong>bootloader</strong> used in the booting process in Linux.</p>
</li>
<li><p>It plays a <strong>critical</strong> role in the boot process by allowing users to choose which operating system to boot when <strong>multiple operating systems</strong> are installed on the same computer.</p>
</li>
<li><p>The <strong>different versions</strong> of GRUB that have been developed over time:</p>
<ul>
<li><p><strong>GRUB 1</strong> --&gt; Getting code from MBR</p>
</li>
<li><p><strong>GRUB 1.5</strong> --&gt; Allows file system to communicate with hardware</p>
</li>
<li><p><strong>GRUB 2.0</strong> --&gt; Main GRUB image, /boot/grub2/grub.conf --&gt;Loading of kernel</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p><strong>Kernel</strong></p>
<ul>
<li><p>It <strong>initializes</strong> &amp; <strong>configures</strong> computer <strong>memory</strong> and <strong>hardware</strong>.</p>
</li>
<li><p><strong>Uncompressed</strong> itself &amp; mount it.</p>
</li>
<li><p>Loads the <strong>required drivers</strong> for it.</p>
</li>
<li><p>Initialize <strong>virtual devices</strong> into the system.</p>
</li>
<li><p><strong>Create</strong> a <strong>root device</strong> mount into <strong>read-only</strong> memory.</p>
</li>
<li><p><strong>Freeze</strong> unused memory.</p>
</li>
</ul>
</li>
<li><p><strong>init.d / system.d</strong></p>
<ul>
<li><p>It is the <strong>first process</strong> (<em>mother of the process</em>) after the kernel step.</p>
</li>
<li><p>Mounting the file system --&gt; /etc/fstab</p>
</li>
<li><p>Starting services</p>
</li>
<li><p>Device attaching to the system</p>
</li>
<li><p>Identify the default target</p>
</li>
</ul>
</li>
<li><p><strong>Run Level</strong></p>
</li>
</ol>
<pre><code class="lang-bash"><span class="hljs-comment">#Commands:</span>

<span class="hljs-comment">#The "who" command is used to display the current run level &amp; system's last reboot time</span>
who -r 
___________________________________________________________________

<span class="hljs-comment">#The "init" command is used to change the system's run level, which represents a specific operating state</span>
<span class="hljs-comment">#Syntax:</span>
init &lt;runlevel&gt;
<span class="hljs-comment">#Example:</span>
init 5 
init 3
___________________________________________________________________

<span class="hljs-comment">#The default target determines the operating state in which the system will boot by default</span>
systemctl set-default multi-user.target
systemctl set-default graphical.target
___________________________________________________________________

<span class="hljs-comment">#This command is used to check the default target</span>
systemctl get-default
___________________________________________________________________

<span class="hljs-comment">#List of Run Levels:</span>
0 - Halt state (poweroff.target)
1 - Single user mode (rescue.target)
2 - Mutli user mode without networking
3 - Mulit user mode with networking
4 - User Definable
5 - GUI (graphical.target)
6 - Reboot
</code></pre>
<hr />
<h3 id="heading-acl"><strong>ACL</strong></h3>
<ul>
<li><p>ACL stands for <strong>Access Control Lists</strong>.</p>
</li>
<li><p>It allows you to give separate permissions to <strong>individual users</strong> or <strong>groups</strong> on <strong>files</strong> and <strong>directories</strong> in a file system.</p>
</li>
<li><p>Allowing you to define more <strong>fine-grained permissions</strong> for specific <strong>users</strong> or <strong>groups</strong>.</p>
</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#To set ACL on a directory:</span>
<span class="hljs-comment">#Syntax:</span>
setfacl -m u:&lt;user&gt;:&lt;perm&gt; &lt;dirname&gt;

<span class="hljs-comment">#Example:</span>
[root@localhost tmp]<span class="hljs-comment"># setfacl -m u:testuser:rwx TestACL/</span>
[root@localhost tmp]<span class="hljs-comment"># ls -ld TestACL/</span>
drwxrwxr-x+ 2 root root 41 Jul 19 12.00 TestACL/

<span class="hljs-comment">#To show the list of users and groups with their respective permissions on the specified file or directory:</span>
<span class="hljs-comment">#Syntax:</span>
getfacl &lt;dirname&gt;
OR
getfacl &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
[root@localhost tmp]<span class="hljs-comment"># getfacl TestACL/</span>
<span class="hljs-comment">#file: TestACL/</span>
<span class="hljs-comment">#owner: root</span>
<span class="hljs-comment">#group: root</span>
user::rwx
user:testuser:rwx
user:robot:rwx
group::r-x
mask::rwx
other::r-x

<span class="hljs-comment">#To remove the ACL (remove a single user at a time):</span>
setfacl -x u:testuser: TestACL/
<span class="hljs-comment">#Verifying...</span>
getfacl TestACL/
user::rwx
user:robot:rwx
group:r-x
mask::rwx
other::r-x

<span class="hljs-comment">#To remove the ACL (remove all users at once):</span>
setfacl -b TestACL/
<span class="hljs-comment">#Verifying...</span>
getfacl TestACL/
user::rwx
group::r-x
other::r-x
</code></pre>
<hr />
<h3 id="heading-processes"><strong>Processes</strong></h3>
<ul>
<li><p>The Process represents the <strong>execution</strong> of a <strong>specific task</strong> or <strong>job</strong> on the system.</p>
</li>
<li><p>Every action you perform on a computer involves one or more processes.</p>
</li>
</ul>
<h3 id="heading-types-of-processes"><strong>Types of Processes</strong></h3>
<ul>
<li><p><strong>Parent and Child Processes</strong> :</p>
<ul>
<li><p>When a new process is created, it is referred to as the "<strong>child process</strong>" and the process that creates it is called the "<strong>parent process</strong>".</p>
</li>
<li><p>Parent processes are processes that <strong>create</strong> and <strong>manage</strong> other processes.</p>
</li>
<li><p>If the process creates <strong>additional processes</strong> as <strong>part</strong> of its <strong>execution</strong>, those are considered <strong>child processes</strong>.</p>
</li>
</ul>
</li>
<li><p><strong>Zombie Processes</strong> :</p>
<ul>
<li><p>The processes that have <strong>completed</strong> their <strong>execution</strong> but <strong>still</strong> have an <strong>entry</strong> in the <strong>process table</strong>.</p>
</li>
<li><p>Zombie processes <strong>do not consume</strong> system resources and are usually <strong>cleaned up automatically</strong> by the system.</p>
</li>
</ul>
</li>
<li><p><strong>Orphan Processes</strong> :</p>
<ul>
<li>Orphan processes are child processes whose parent processes have <strong>terminated unexpectedly</strong> before collecting their <strong>exit status.</strong></li>
</ul>
</li>
</ul>
<h3 id="heading-process-state"><strong>Process State</strong></h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1689780128576/3a5f97e6-2305-4c3d-af2f-06a1cb3bcff0.jpeg" alt class="image--center mx-auto" /></p>
<ul>
<li><p>A process state refers to the <strong>current condition</strong> or <strong>status</strong> of a <strong>running process</strong>.</p>
</li>
<li><p>The process state indicates what the process is currently <strong>doing</strong> or <strong>waiting</strong> for in the system.</p>
</li>
</ul>
<hr />
<h3 id="heading-commands-related-to-processes-in-linux"><strong>Commands Related to Processes in Linux</strong></h3>
<p><strong>Top Command</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1689788400317/2b9f0c69-715e-4f36-b379-5dc3c2cae6da.png" alt class="image--center mx-auto" /></p>
<pre><code class="lang-bash"><span class="hljs-comment">#This command provides real-time dynamic monitoring of system processes, </span>
<span class="hljs-comment">#CPU usage, memory utilization, and other system statistics in an interactive shell</span>
[root@localhost ~]<span class="hljs-comment"># top</span>
</code></pre>
<p><strong>To list the processes that have "&lt;word&gt;" in it</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment">#Listing the processes having word "top" in it</span>
<span class="hljs-comment">#Used to list all running processes and </span>
<span class="hljs-comment"># filter the output to display only the lines containing word "top" using grep command.</span>
[root@localhost ~]<span class="hljs-comment"># ps -ef|grep top</span>
</code></pre>
<p><strong>To assign higher or lower priority to a new process</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
nice -n &lt;nicenessValue&gt; <span class="hljs-built_in">command</span>

<span class="hljs-comment">#Example:</span>
[root@localhost ~]<span class="hljs-comment"># nice -n -5 top</span>
</code></pre>
<ul>
<li><p>The "<strong>nice</strong>" command is used to execute a command to modify a niceness value.</p>
</li>
<li><p>The nice command is used when starting a new process to set its <strong>initial priority.</strong></p>
</li>
<li><p>The niceness value is an integer that ranges from -<strong>20</strong> to +<strong>20</strong>.</p>
</li>
<li><p>The <strong>lower values</strong> indicate <strong>higher priority</strong>. A process with a higher priority (<em>lower niceness value</em>) will be running more frequently compared to processes with a lower priority.</p>
</li>
</ul>
<p><strong>To assign higher or lower priority to an existing process using its PID</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
renice -n &lt;niceness_value&gt; &lt;PID&gt;

<span class="hljs-comment">#Example:</span>
[root@localhost ~]<span class="hljs-comment"># renice -5 3030</span>
<span class="hljs-comment">#Here, 3030 is pid for command top</span>
</code></pre>
<p><strong>To terminate, kill, resume or suspend a process</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
<span class="hljs-built_in">kill</span> &lt;signal&gt; &lt;PID&gt;

<span class="hljs-comment">#Signals:</span>
Terminate : -15
Kill : -9
Resume : -18
Suspend : -19

<span class="hljs-comment">#Example:</span>
<span class="hljs-built_in">kill</span> -9 3030
OR
<span class="hljs-built_in">kill</span> -15 3745
</code></pre>
<p><strong>Jobs command</strong></p>
<ul>
<li>The command "<strong>jobs</strong>" is useful when you are running multiple background processes and need to <strong>keep track</strong> of their <strong>status</strong> or <strong>interact</strong> with them.</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#Command</span>
[root@localhost ~]<span class="hljs-comment"># jobs</span>
</code></pre>
<hr />
<h3 id="heading-alias"><strong>Alias</strong></h3>
<ul>
<li><p>An alias is a <strong>user-defined shortcut</strong> or <strong>nickname</strong> for a <strong>command</strong> or a <strong>sequence</strong> of commands.</p>
</li>
<li><p>Aliases allow users to create their <strong>shorthand notation</strong> for <strong>frequently</strong> used or complex commands, making it <strong>easier</strong> and <strong>faster</strong> to execute them.</p>
</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#Defining an Alias (Syntax):</span>
<span class="hljs-built_in">alias</span> aliasName=<span class="hljs-string">"command_or_commands"</span>

<span class="hljs-comment">#Example:</span>
<span class="hljs-built_in">alias</span> viraj=<span class="hljs-string">"ls -lrt"</span>

<span class="hljs-comment">#You can define the alias in the .bashrc or .bash_aliases file</span>
<span class="hljs-comment">#Defining the alias in the interactive terminal/shell is temporary, to define it permanently write the alias in .bashrc file</span>
</code></pre>
<hr />
]]></content:encoded></item><item><title><![CDATA[Logs, YUM & RPM, Repositories, Cron in Linux]]></title><description><![CDATA[These topics are covered in today's session.
Logs

In Linux, Logs refer to the recorded information about system events, activities, and processes that are stored in log files.

Logs are essential for developers to troubleshoot issues, monitor system...]]></description><link>https://viraj-verse.hashnode.dev/logs-yum-rpm-repositories-cron-in-linux</link><guid isPermaLink="true">https://viraj-verse.hashnode.dev/logs-yum-rpm-repositories-cron-in-linux</guid><category><![CDATA[Linux]]></category><category><![CDATA[#learnwithpra9]]></category><category><![CDATA[linux kernel]]></category><category><![CDATA[linux for beginners]]></category><category><![CDATA[linux-commands]]></category><dc:creator><![CDATA[Viraj Nalbalwar]]></dc:creator><pubDate>Mon, 17 Jul 2023 20:10:31 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1689624613687/67d10392-0a9c-49bb-b764-9a92a30fabe9.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>These topics are covered in today's session.</p>
<h3 id="heading-logs"><strong>Logs</strong></h3>
<ul>
<li><p>In Linux, <strong>Logs</strong> refer to the recorded information about <strong>system events</strong>, <strong>activities</strong>, and <strong>processes</strong> that are stored in log files.</p>
</li>
<li><p>Logs are essential for developers to <strong>troubleshoot issues</strong>, <strong>monitor system</strong> <strong>performance</strong>, and <strong>maintain system security</strong>.</p>
</li>
</ul>
<hr />
<h3 id="heading-some-of-the-logs-in-linux"><strong>Some of the logs in Linux</strong></h3>
<ol>
<li><p>Kernel Log</p>
</li>
<li><p>Boot Log</p>
</li>
<li><p>CUPS</p>
</li>
<li><p>dmesg</p>
</li>
<li><p>fail</p>
</li>
<li><p>yum</p>
</li>
<li><p>cron</p>
</li>
<li><p>secure</p>
</li>
<li><p>mail</p>
</li>
<li><p>wtmp</p>
</li>
</ol>
<hr />
<h3 id="heading-rsyslogconf"><strong>rsyslog.conf</strong></h3>
<ul>
<li><p>The "<strong>rsyslog.conf</strong>" file is the main configuration file for the rsyslog service in Linux.</p>
</li>
<li><p>The file is typically located in the "<strong><em>/etc/rsyslog.conf</em></strong>" or "<strong><em>/etc/rsyslog.d/</em></strong>" directory, <strong>depending</strong> on the Linux distribution.</p>
</li>
<li><p>The rsyslog.conf file contains directives and rules that how log messages are <strong>received</strong>, <strong>processed</strong>, and <strong>forwarded</strong> by rsyslog.</p>
</li>
<li><p>It allows administrators to <strong>customize</strong> the behavior of the logging system according to their specific requirements.</p>
</li>
</ul>
<hr />
<h3 id="heading-facilities-andamp-priorities"><strong>Facilities &amp; Priorities</strong></h3>
<ul>
<li>Facilities and Priorities are used to <strong>categorize</strong> and <strong>filter</strong> log messages.</li>
</ul>
<p><strong>Facilities:</strong></p>
<ul>
<li><p>Facilities represent <strong>different sources</strong> that <strong>generate</strong> log messages.</p>
</li>
<li><p>Each log message is associated with a <strong>facility</strong>, which helps <strong>identify</strong> its <strong>source</strong> or <strong>origin</strong>.</p>
</li>
<li><p>Some common facilities include :</p>
<ul>
<li><p><strong>auth</strong>: Authentication-related messages.</p>
</li>
<li><p><strong>cron</strong>: Messages from the cron scheduler.</p>
</li>
<li><p><strong>authpriv</strong>: Authentication-related log messages with enhanced privacy considerations.</p>
</li>
<li><p><strong>mail</strong>: Mail server-related messages.</p>
</li>
<li><p><strong>user</strong>: User-level messages.</p>
</li>
</ul>
</li>
</ul>
<p><strong>Priorities:</strong></p>
<ul>
<li><p>Priorities indicate the <strong>importance</strong> of a <strong>log</strong> entry.</p>
</li>
<li><p>They help determine the <strong>urgency</strong> or <strong>criticality</strong> of a log message.</p>
</li>
<li><p>Some common priorities include :</p>
<ul>
<li><p><strong>debug</strong>: Detailed debugging information.</p>
</li>
<li><p><strong>info</strong>: General information messages.</p>
</li>
<li><p><strong>notice</strong>: Important but non-error conditions.</p>
</li>
<li><p><strong>warning</strong>: Indications of potential issues.</p>
</li>
<li><p><strong>err</strong>: Errors that may impact system functionality.</p>
</li>
<li><p><strong>critical</strong>: Critical errors requiring immediate attention.</p>
</li>
<li><p><strong>alert</strong>: Alerts requiring immediate action.</p>
</li>
<li><p><strong>emerg</strong>: The most severe level, indicating an emergency condition.</p>
</li>
</ul>
</li>
</ul>
<hr />
<h3 id="heading-to-create-your-custom-log"><strong>To Create Your Custom Log</strong></h3>
<p>Creating a custom log file in /var/log/</p>
<pre><code class="lang-bash"><span class="hljs-comment">#Traversing to /var/log/ directory :</span>
[root@localhost ~]<span class="hljs-comment"># cd /var/log/</span>

<span class="hljs-comment">#Creating a file myCustom.log :</span>
[root@localhost <span class="hljs-built_in">log</span>]<span class="hljs-comment"># touch myCustom.log</span>

<span class="hljs-comment">#Create a facility and priority in rsyslog.conf file :</span>
[root@localhost ~]<span class="hljs-comment"># vim /etc/rsyslog.conf</span>

<span class="hljs-comment">#Add your facilities and priorities in the rsyslog.conf file :</span>
<span class="hljs-comment">#Adding a log selector that matches every facility and priority and give the file name to get the log messages ...</span>
*.*             /var/<span class="hljs-built_in">log</span>/myCustom.log
<span class="hljs-comment">#Save the file</span>

<span class="hljs-comment">#Restart the "rsyslog.service: service :</span>
systemctl restart rsyslog.service

<span class="hljs-comment">#Use tail command to get the dynamic output in the terminal :</span>
<span class="hljs-comment">#Syntax:</span>
tail -f &lt;pathToFile&gt;
<span class="hljs-comment">#Example:</span>
tail -f /var/<span class="hljs-built_in">log</span>/myCustom.log

<span class="hljs-comment">#Try to switch user to another user and check myCustom.log file</span>
[root@localhost ~]<span class="hljs-comment"># su - vnalbalwar</span>
<span class="hljs-comment">#You will get the log messages about the another user logged in.</span>
</code></pre>
<hr />
<h3 id="heading-log-rotation"><strong>Log Rotation</strong></h3>
<ul>
<li><p>Log rotation is the process of <strong>managing</strong> log files by <strong>automatically <em>archiving</em></strong>, <strong><em>compressing</em></strong>, and eventually <strong><em>removing</em> old</strong> log files to prevent them from growing too large and consuming excessive disk space.</p>
</li>
<li><p>We can configure or customize the log rotation according to your specific requirements.</p>
</li>
<li><p>Just navigate to the file "<strong>logrotate.conf</strong>" and edit it according to your need.</p>
</li>
<li><p>Options like <strong>rotate files weekly</strong>, <strong>create new log files after rotating the old ones</strong> can be customized.</p>
</li>
</ul>
<hr />
<h3 id="heading-yum-andamp-rpm"><strong>YUM &amp; RPM</strong></h3>
<ul>
<li>YUM and RPM are the package installer in Linux.</li>
</ul>
<p><strong>YUM :</strong></p>
<ul>
<li><p>YUM stands for "<strong>Yellowdog Updater, Modified</strong>".</p>
</li>
<li><p>It is a <strong>high-level</strong> package management utility.</p>
</li>
<li><p>When you request to <strong>install</strong> or <strong>update</strong> a package, Yum checks for and installs any <strong>required dependencies</strong> as well.</p>
</li>
<li><p>Yum <strong>fetches</strong> packages from software repositories.</p>
</li>
</ul>
<p><strong>Yum Commands :</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>

<span class="hljs-comment">#Used to install a package from the configured repositories</span>
yum install &lt;packagename&gt;

<span class="hljs-comment">#The -y option is used to automatically answer "yes" to any prompts during the installation process</span>
yum install &lt;packagename&gt; -y

<span class="hljs-comment">#Used to remove or uninstall a package from the system</span>
yum remove&lt;packagename&gt;

<span class="hljs-comment">#The -y option automatically answers "yes" to any prompts during the removal process</span>
yum remove &lt;packagename&gt; -y 

<span class="hljs-comment">#Lists all installed packages that match the specified &lt;packagename&gt;</span>
yum list &lt;packagename&gt;

<span class="hljs-comment">#Searches the repositories for packages that match the specified &lt;packagename&gt;</span>
yum search &lt;packagename&gt;

<span class="hljs-comment">#Displays detailed information about the specified &lt;packagename&gt;</span>
yum info &lt;packagename&gt;

<span class="hljs-comment">#Updates all installed packages to their latest available versions</span>
yum update -y
</code></pre>
<p><strong>RPM :</strong></p>
<ul>
<li><p>RPM stands for <strong>Red Hat Package Manager</strong>.</p>
</li>
<li><p>It s a <strong>low-level package management system</strong> used in RPM-based Linux distributions.</p>
</li>
<li><p>RPM <strong>does not</strong> automatically handle package dependencies.</p>
</li>
<li><p>You must <strong>manually install</strong> any required dependencies before installing an RPM package.</p>
</li>
</ul>
<p><strong>RPM Commands :</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>

<span class="hljs-comment">#Used to install an RPM package, where, </span>
<span class="hljs-comment">#'i' option indicates installation, </span>
<span class="hljs-comment">#-v enables verbose output during installation, </span>
<span class="hljs-comment">#-h displays a hash mark progress indicator during installation</span>
rpm -ivh &lt;packagename&gt;

<span class="hljs-comment">#Queries an installed RPM package to retrieve a list of files it contains</span>
rpm -qpr &lt;packagename&gt;

<span class="hljs-comment">#The --nodeps option allows the installation to proceed even if there are unmet dependencies</span>
rpm -ivh --nodeps &lt;packagename&gt;

<span class="hljs-comment">#Queries the system to check if a package with the specified name is installed</span>
rpm -q &lt;packagename&gt;

<span class="hljs-comment">#Lists all installed packages sorted by their installation timestamp, with the most recently installed package displayed at the top.</span>
rpm -qa -last

<span class="hljs-comment">#Lists all installed packages on the system</span>
rpm -qa 

<span class="hljs-comment">#Used to upgrade an already installed package to a newer version</span>
rpm -uvh &lt;packagename&gt;

<span class="hljs-comment">#Used to uninstall or remove an installed package</span>
rpm -evv &lt;packagename&gt;
</code></pre>
<p><strong>APT Commands :</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>

<span class="hljs-comment">#Updates the local package database with the latest information from the repositories</span>
apt-get update -y

<span class="hljs-comment">#Verifies that the package dependencies are met and the package files are intact</span>
apt-get check &lt;packagename&gt;

<span class="hljs-comment">#Upgrades the specified packages to their latest available versions</span>
apt-get upgrade &lt;packgame&gt;

<span class="hljs-comment">#Installs a specific version of a package</span>
apt-get install &lt;pkgname&gt;=&lt;versionno&gt;

<span class="hljs-comment">#Installs multiple packages in a single command</span>
apt-get install &lt;pkg1&gt; &lt;pkg2&gt;

<span class="hljs-comment">#Downloads the specified packages without installing them</span>
apt-get install -download-only &lt;pkgname&gt;
</code></pre>
<hr />
<h3 id="heading-repositories"><strong>Repositories</strong></h3>
<ul>
<li><p>A repository is a <strong>centralized storage</strong> location that contains software <strong>packages</strong>, <strong>metadata</strong>, and <strong>information</strong> about <strong>dependencies</strong>.</p>
</li>
<li><p>It serves as a <strong>source</strong> for <strong>obtaining</strong> and <strong>managing</strong> software packages for an operating system.</p>
</li>
<li><p>The repo's are stored at "<strong>/etc/yum.repos.d/redhat.repo",</strong> you can navigate there using the cd command and look up the file.</p>
</li>
</ul>
<hr />
<h3 id="heading-journalctl"><strong>Journalctl</strong></h3>
<ul>
<li><p>Journalctl is a command-line utility in Linux that <strong>allows</strong> you and is <strong>responsible</strong> to <strong>access</strong>, <strong>view</strong> and <strong>collect</strong> logs from the <strong>systemd</strong> journal.</p>
</li>
<li><p>The systemd journal is a <strong>centralized</strong> logging system that <strong>collects</strong> and <strong>stores</strong> log messages generated by various components of the system.</p>
</li>
</ul>
<hr />
<h3 id="heading-cron"><strong>Cron</strong></h3>
<ul>
<li><p>Cron is a <strong>time-based</strong> job scheduling utility, in short, it's a <strong>scheduler</strong>.</p>
</li>
<li><p>It allows users to <strong>schedule</strong> and <strong>automate</strong> the execution of commands or scripts at specific <strong>intervals</strong>, such as <strong><em>daily</em></strong>, <strong><em>weekly</em></strong>, <strong><em>monthly</em></strong>, or at specific times of the day.</p>
</li>
</ul>
<p><strong>Cron Commands :</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>

<span class="hljs-comment">#Opens the crontab file for editing</span>
<span class="hljs-comment">#It allows you to add, modify, or remove cron jobs for the current user.</span>
crontab -e

<span class="hljs-comment">#Lists the current user's crontab entries, displaying the scheduled cron jobs.</span>
crontab -l

<span class="hljs-comment">#Removes the current user's crontab entries, removing all scheduled cron jobs.</span>
crontab -r
</code></pre>
<p><strong>To define cron jobs :</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment">#There are 6 fields in crontab file :</span>
<span class="hljs-comment">#Syntax:</span>
&lt;minute&gt; &lt;hours&gt; &lt;date&gt; &lt;month&gt; &lt;day&gt; &lt;<span class="hljs-built_in">command</span>&gt;
</code></pre>
<hr />
<h3 id="heading-crontab-example"><strong>Crontab Example:</strong></h3>
<p>E.g. Write a cron job to print "<strong>Hello Linux</strong>" in a file every <strong>1</strong> minute <strong>forever</strong>.</p>
<pre><code class="lang-bash"><span class="hljs-comment">#Create a file sayHelloForever at /tmp/ directory...</span>
[root@localhost tmp]<span class="hljs-comment"># touch sayHelloForever</span>

<span class="hljs-comment">#Open the crontab file :</span>
[root@localhost ~]<span class="hljs-comment"># crontab -e</span>

<span class="hljs-comment">#Enter the fields in the above manner given...</span>
* * * * * <span class="hljs-built_in">echo</span> <span class="hljs-string">"Hello Linux"</span> &gt;&gt; /tmp/sayHelloForever
<span class="hljs-comment">#Save the file</span>

<span class="hljs-comment">#To get the dynamic output in terminal use tail command...</span>
[root@localhost ~]<span class="hljs-comment"># tail -f /tmp/sayHelloForever</span>
Hello Linux
Hello Linux
....

<span class="hljs-comment">#You can now list the crontab using...</span>
[root@localhost ~]<span class="hljs-comment"># crontab -l</span>
* * * * * <span class="hljs-built_in">echo</span> <span class="hljs-string">"Hello Linux"</span> &gt;&gt; /tmp/sayHelloForever
</code></pre>
<hr />
]]></content:encoded></item><item><title><![CDATA[Find & Locate, SSH (Secure Shell), Password-Less SSH]]></title><description><![CDATA[These are the topics that are covered in today's session.
Pranav Jambare
Find Command:

The find command is used to search for files and directories based on various criteria such as name, size, type, etc.

It starts searching from a specified direct...]]></description><link>https://viraj-verse.hashnode.dev/find-locate-ssh-secure-shell</link><guid isPermaLink="true">https://viraj-verse.hashnode.dev/find-locate-ssh-secure-shell</guid><category><![CDATA[Linux]]></category><category><![CDATA[linux for beginners]]></category><category><![CDATA[#learnwithpra9]]></category><category><![CDATA[linux-commands]]></category><category><![CDATA[Programming Blogs]]></category><dc:creator><![CDATA[Viraj Nalbalwar]]></dc:creator><pubDate>Sun, 16 Jul 2023 13:26:59 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1689513878485/fc1e322f-1577-488d-b0b5-ed623b82fdee.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>These are the topics that are covered in today's session.</p>
<p><a class="user-mention" href="https://hashnode.com/@AutomateMaster">Pranav Jambare</a></p>
<h3 id="heading-find-command"><strong>Find Command:</strong></h3>
<ul>
<li><p>The <strong>find</strong> command is used to <strong><em>search</em></strong> for <strong>files</strong> and <strong>directories</strong> based on various criteria such as <strong>name</strong>, <strong>size</strong>, <strong>type</strong>, etc.</p>
</li>
<li><p>It starts searching from a <strong>specified directory</strong> provided in the command and <strong>traverses</strong> the <strong>entire</strong> directory structure.</p>
</li>
<li><p>It scans the file system <strong>dynamically</strong> in <strong>real time</strong>, examining each file and directory individually.</p>
</li>
</ul>
<p>Thus, it may take longer to complete, especially in large file systems.</p>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
 find &lt;path&gt; &lt;expression&gt;
</code></pre>
<hr />
<h3 id="heading-to-find-files-based-on-their-name-in-linux"><strong>To find files based on their name in Linux:</strong></h3>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax: (Case-Sensitive Search)</span>
find &lt;path&gt; -name &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
<span class="hljs-comment">#To find the file named sampleFile in /tmp directory:</span>
[root@localhost /]<span class="hljs-comment"># find /tmp -name sampleFile</span>
/tmp/myCollab/sampleFile

<span class="hljs-comment">#Syntax: (Case-Insensitive Search)</span>
find &lt;path&gt; -iname &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
<span class="hljs-comment">#To find the file named sampleFile in /tmp directory:</span>
[root@localhost /]<span class="hljs-comment"># find /tmp -iname SamPLefile</span>
/tmp/myCollab/sampleFile
</code></pre>
<hr />
<h3 id="heading-to-find-the-files-owned-by-the-specific-user-in-linux"><strong>To find the files owned by the specific user in Linux:</strong></h3>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
find &lt;path&gt; -user &lt;username&gt;

<span class="hljs-comment">#Example:</span>
<span class="hljs-comment"># To search for files owned by testuser starting from the root directory:</span>
[root@localhost /]<span class="hljs-comment"># find / -user testuser</span>

<span class="hljs-comment">#To search for files owned by vnalbalwar starting from the /tmp directory:</span>
[root@localhost /]<span class="hljs-comment"># find /tmp -user vnalbalwar</span>
</code></pre>
<hr />
<h3 id="heading-to-find-files-and-delete-them-using-the-rm-command-in-linux"><strong>To find files and delete them using the rm command in Linux:</strong></h3>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
find &lt;path&gt; -name &lt;filename&gt; -<span class="hljs-built_in">exec</span> rm -rf {} \;

<span class="hljs-comment">#Example:</span>
<span class="hljs-comment"># The sampleFile will get removed:</span>
[root@localhost /]<span class="hljs-comment"># find /tmp -name sampleFile -exec rm -rf {} \;</span>
</code></pre>
<hr />
<h3 id="heading-to-find-files-with-specific-permission-in-linux"><strong>To find files with specific permission in Linux:</strong></h3>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
find &lt;path&gt; -perm &lt;permissionNum&gt; 

<span class="hljs-comment">#Example:</span>
<span class="hljs-comment">#To search for files having permission 700 starting from root directory: </span>
[root@localhost /]<span class="hljs-comment"># find / -perm 700</span>
</code></pre>
<hr />
<h3 id="heading-to-find-the-directories-or-files-in-linux"><strong>To find the directories or files in Linux:</strong></h3>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax: (For searching directories)</span>
find &lt;path&gt; -<span class="hljs-built_in">type</span> d 

<span class="hljs-comment">#Syntax: (For searching files)</span>
find &lt;path&gt; -<span class="hljs-built_in">type</span> f

<span class="hljs-comment">#Example:</span>
<span class="hljs-comment">#Find all the directories starting from root directory :</span>
[root@localhost /]<span class="hljs-comment"># find / -type d</span>

<span class="hljs-comment">#Find all the files starting from /tmp directory:</span>
[root@localhost /]<span class="hljs-comment"># find /tmp -type f</span>
</code></pre>
<hr />
<h3 id="heading-locate-command"><strong>Locate Command:</strong></h3>
<ul>
<li><p>The <strong>locate</strong> command is used to <strong>statically</strong> and <strong>quickly</strong> find files and directories by searching in the <strong>pre-built</strong> database.</p>
</li>
<li><p>It is <strong>faster</strong> than the <strong>find</strong> command but may <strong>not provide</strong> real-time results as the <strong>database</strong> needs to be updated <strong>periodically</strong>.</p>
</li>
</ul>
<p>To update the database :</p>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
updatedb
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
locate &lt;keyword&gt;

<span class="hljs-comment">#Example:</span>
locate sampleFile
/home/vnalbalwar/sampleFile
</code></pre>
<hr />
<h3 id="heading-ssh"><strong>SSH:</strong></h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1689513090097/969a2ce4-349e-41be-9dbf-5b34f0d80ca6.jpeg" alt class="image--center mx-auto" /></p>
<ul>
<li><p>SSH stands for <strong>Secure Shell</strong>.</p>
</li>
<li><p>It provides a secure way to <strong>access</strong> and <strong>manage</strong> remote systems.</p>
</li>
<li><p>It allows you to securely <strong>connect</strong> to a remote server and execute <strong>commands</strong>, <strong>transfer</strong> files, etc.</p>
</li>
<li><p>When you establish an SSH connection, the data transmitted between the client and the server is encrypted.</p>
</li>
<li><p>There are two cryptographic keys for SSH :</p>
<ul>
<li><p><strong>Public Key:</strong> The public key is used for <strong>encryption</strong> and can be freely shared with others. When someone wants to send you <strong>encrypted</strong> data, they will use <strong>your public key</strong> to <strong>encrypt</strong> it, ensuring that only you, with the <strong>corresponding private</strong> key, can <strong>decrypt</strong> and access the information.</p>
</li>
<li><p>Private Key: The private key is kept <strong>secret</strong> and should <strong>never</strong> be <strong>shared</strong>. It is used to <strong>decrypt</strong> messages encrypted with your public key and to <strong>prove</strong> your <strong>identity</strong> during the <strong>SSH</strong> authentication process.</p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-steps-to-create-an-ssh-connection">Steps to create an SSH connection:</h3>
<ul>
<li>To setup an SSH connection you need these packages installed on your system: <strong><em>(openssh-server, openssh-client)</em></strong></li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
yum install &lt;packagename&gt;

<span class="hljs-comment">#Installing required packages...</span>
yum install openssh-server
yum install openssh-client
</code></pre>
<ul>
<li>To check whether port 22 is active/open or not for SSH establishment:</li>
</ul>
<pre><code class="lang-bash">netstat -tunlp|grep 22
</code></pre>
<ul>
<li>To check the status of the service:</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
systemctl status &lt;servicename&gt;

<span class="hljs-comment">#Checking...</span>
systemctl status sshd
</code></pre>
<ul>
<li>To start, stop &amp; restart the service:</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#Start</span>
systemctl start &lt;servicename&gt;

<span class="hljs-comment">#Stop</span>
systemctl stop &lt;servicename&gt;

<span class="hljs-comment">#Restart</span>
systemctl restart &lt;servicename&gt;
</code></pre>
<ul>
<li>To establish the connection between the client and the remote system:</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
ssh &lt;username&gt;@&lt;userIP&gt;

<span class="hljs-comment">#Example:</span>
ssh vnalbalwar@192.168.0.109
</code></pre>
<hr />
<h3 id="heading-to-allow-and-deny-users-to-connect-to-the-specific-server"><strong>To allow and deny users to connect to the specific server:</strong></h3>
<pre><code class="lang-bash"><span class="hljs-comment">#You can navigate to /etc/ssh/sshd_config :</span>
[root@localhost ~]<span class="hljs-comment"># vim /etc/ssh/sshd_config</span>

<span class="hljs-comment">#Add these commands there and save the file : (Syntax):</span>
AllowUsers &lt;username&gt;
DenyUsers &lt;username&gt;

<span class="hljs-comment">#Example</span>
AllowUsers viraj
DenyUsers thisIsMe

<span class="hljs-comment">#Now restart the service...</span>
[root@localhost ~]<span class="hljs-comment"># systemctl restart sshd</span>
<span class="hljs-comment">#And check status...</span>
[root@localhost ~]<span class="hljs-comment"># systemctl status sshd</span>
</code></pre>
<hr />
<ul>
<li><h3 id="heading-to-allow-and-deny-the-networks-to-connect-to-the-specific-server"><strong>To allow and deny the networks to connect to the specific server:</strong></h3>
</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#You can navigate and edit the file /etc/host.allow or /etc/host.deny</span>
[root@localhost ~]<span class="hljs-comment"># vim /etc/host.allow</span>

<span class="hljs-comment">#Add an entry in the hosts.allow file to allow access from the specific IP address:</span>
<span class="hljs-comment">#Syntax:</span>
&lt;service&gt;: &lt;IP address&gt;
<span class="hljs-comment">#Example:</span>
sshd: 192.168.0.109
<span class="hljs-comment">#Restart the ssh service</span>
[root@localhost ~]<span class="hljs-comment"># systemctl restart sshd</span>
<span class="hljs-comment">#Same can be done for host.deny file by adding the IP address those which should not connect to the server</span>
</code></pre>
<hr />
<h3 id="heading-password-less-ssh"><strong>Password-Less SSH:</strong></h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1689613374703/76806938-24e2-43bf-8caf-28d6619da096.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p><strong>Password-less SSH</strong> is a method of securely accessing remote systems or servers <strong>without</strong> the need for a <strong>password.</strong></p>
</li>
<li><p>It relies on <strong>cryptographic</strong> key pairs, consisting of a <strong>private</strong> key and a <strong>public</strong> key, to <strong>authenticate</strong> the connection between a <strong>client</strong> and a <strong>server</strong>.</p>
</li>
<li><p>It can be considered more secure than passwords since it uses public-private key cryptography.</p>
</li>
</ul>
<hr />
<h3 id="heading-steps-to-setup-the-password-less-ssh"><strong>Steps to setup the Password-Less SSH:</strong></h3>
<ul>
<li><h3 id="heading-generating-the-ssh-keys-on-the-local-machine"><strong>Generating the SSH keys on the local machine:</strong></h3>
</li>
<li><p>The primary purpose of the "<strong>ssh-keygen</strong>" command is to generate a new SSH key pair.</p>
</li>
<li><p>It prompts the user for information and <strong>creates</strong> both a <strong>private</strong> key and a corresponding <strong>public</strong> key.</p>
</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#Command:</span>
ssh-keygen
</code></pre>
<ul>
<li>The <strong>default directories</strong> for public and private keys are :</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#For public key:</span>
/home/&lt;userdirectory&gt;/.ssh/id_rsa.pub

<span class="hljs-comment">#For private key:</span>
/home/&lt;userdirectory&gt;/.ssh/id_rsa
</code></pre>
<h3 id="heading-copying-the-users-public-key-to-the-remote-server-and-enabling-the-ssh-authentication"><strong>Copying the user's public key to the remote server, and enabling the SSH authentication:</strong></h3>
<pre><code class="lang-bash"><span class="hljs-comment">#Command:</span>
ssh-copy-id -i id_rsa.pub username@IP

<span class="hljs-comment">#Example:</span>
ssh-copy-id -i id_rsa.pub root@192.168.0.5
</code></pre>
<p>Where,</p>
<p><strong>ssh-copy-id</strong> --&gt; It is used to copy a user's public key to a remote server.</p>
<p><strong>-i id_rsa.pub</strong> --&gt; Specifies the path to the public key file that will be copied.</p>
<p><strong>root@192.168.0.5</strong> --&gt; Represents the username and IP address of the remote server.</p>
<h3 id="heading-establishing-the-connection-with-the-client"><strong>Establishing the connection with the client:</strong></h3>
<ul>
<li>We can now <strong>connect</strong> to the <strong>remote server</strong> using SSH <strong>without</strong> any password.</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
ssh username@IP

<span class="hljs-comment">#Example:</span>
ssh root@192.168.0.5
</code></pre>
<hr />
]]></content:encoded></item><item><title><![CDATA[Soft Link, Hard Link, Permissions & Special Permission In Linux]]></title><description><![CDATA[These are the topics that are covered in today's session.
Pranav Jambare
Soft Link:


A soft link is also known as a symbolic link or symlink.

It is a special type of file that acts as a pointer or as a reference to another file or directory.

If th...]]></description><link>https://viraj-verse.hashnode.dev/soft-link-hard-link-permissions-special-permission-in-linux</link><guid isPermaLink="true">https://viraj-verse.hashnode.dev/soft-link-hard-link-permissions-special-permission-in-linux</guid><category><![CDATA[Linux]]></category><category><![CDATA[linux kernel]]></category><category><![CDATA[#learnwithpra9]]></category><category><![CDATA[#Linuxcommand]]></category><dc:creator><![CDATA[Viraj Nalbalwar]]></dc:creator><pubDate>Fri, 14 Jul 2023 17:53:30 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1689357134796/c9753c0c-0de2-46a4-9ef9-a5a1e4bd96c5.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>These are the topics that are covered in today's session.</p>
<p><a class="user-mention" href="https://hashnode.com/@AutomateMaster">Pranav Jambare</a></p>
<h3 id="heading-soft-link"><strong>Soft Link:</strong></h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1689347949055/f528d4e0-4497-4a75-aa57-59120bbfa198.jpeg?auto=compress,format&amp;format=webp" alt class="image--center mx-auto" /></p>
<ul>
<li><p>A soft link is also known as a <strong>symbolic link</strong> or <strong>symlink.</strong></p>
</li>
<li><p>It is a special type of file that acts as a <strong>pointer</strong> or as a <strong>reference</strong> to another <strong>file</strong> or <strong>directory</strong>.</p>
</li>
<li><p>If the original file is <strong>deleted</strong>, the soft link will be pointing to a file that does <strong>not exist anymore</strong> and will be considered a <strong>corrupted</strong> link.</p>
</li>
<li><p>Creating a Soft Link File :</p>
</li>
</ul>
<p><strong>COPY</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
ln -s &lt;mainFile&gt; &lt;SLFile&gt;

<span class="hljs-comment">#Example:</span>
ln -s myFile mySLFile
</code></pre>
<ul>
<li><p>By default, the link count of a file in Linux is always <strong>1</strong>.</p>
</li>
<li><p><strong>Verifying</strong> the linking of the soft link file with the original file :</p>
</li>
</ul>
<p><strong>COPY</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment">#Verifying...</span>
ls -l
lrwxrwxrwx 1 root root 8 Jul 14 12.00 mySLFile -&gt; myFile
</code></pre>
<hr />
<h3 id="heading-hard-link"><strong>Hard Link:</strong></h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1689348035576/3a8b8ed5-388d-4b0c-964a-e04a496df5e4.jpeg?auto=compress,format&amp;format=webp" alt class="image--center mx-auto" /></p>
<ul>
<li><p>A hard link acts as a <strong>copy</strong> of the <strong>original</strong> file.</p>
</li>
<li><p>It accesses the data available in the original file.</p>
</li>
<li><p>If the original file is <strong>deleted</strong>, the hard link to the file will <strong>still contain</strong> the <strong>data</strong> of that file.</p>
</li>
<li><p>After the hard link is created, the link count of both the <strong>original</strong> file and the <strong>hard</strong> <strong>link</strong> file becomes "<strong>2</strong>".</p>
</li>
<li><p>Creating a Hard Link File :</p>
</li>
</ul>
<p><strong>COPY</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
ln &lt;mainFile&gt; &lt;HLFile&gt;

<span class="hljs-comment">#Example:</span>
ln myFile myHLFile
</code></pre>
<ul>
<li>Verifying the Hard Link File :</li>
</ul>
<p><strong>COPY</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment">#Verifying...</span>
ls -l
<span class="hljs-comment">#The link count becomes 2 after the hard link file is created...</span>
-rw-rw-r-- 2 root root 27 Jul 14 12:00 myHLFile
-rw-rw-r-- 2 root root 27 Jul 14 12:00 myFile
</code></pre>
<hr />
<h3 id="heading-permissions"><strong>Permissions:</strong></h3>
<ul>
<li><p>Permissions are a set of <strong>attributes</strong> that determine the access <strong>rights</strong> and <strong>restrictions</strong> for <strong>files</strong> and <strong>directories</strong>.</p>
</li>
<li><p>There are three types of permissions: <strong>Read</strong>, <strong>Write</strong>, and <strong>Execute</strong>.</p>
</li>
<li><p>These permissions are assigned to three different categories of users: the <strong>owner</strong> of the file, the <strong>group</strong> associated with the file, and <strong>other</strong> <strong>users</strong> who are not the owner or part of the group.</p>
</li>
<li><p><strong>Read</strong> (r): Allows a user to <strong>view</strong> the contents of a <strong>file</strong> or <strong>list</strong> the contents of a <strong>directory</strong>.</p>
</li>
<li><p><strong>Write</strong> (w): Allows a user to <strong>modify</strong> or <strong>delete</strong> a file, or <strong>create</strong>, <strong>delete</strong>, or <strong>rename</strong> files within a directory.</p>
</li>
<li><p><strong>Execute</strong> (x): Allows a user to <strong>execute</strong> a file <strong><em>as a program</em></strong> or <strong><em>access a directory</em></strong> to traverse its contents.</p>
</li>
<li><p>Permissions can be displayed using the following command :</p>
</li>
</ul>
<p><strong>COPY</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
ls -l &lt;filename&gt;
-rw-rw-r-- 1 myUser myGroup 27 Jul 14 12:00 mainFile
</code></pre>
<ul>
<li><p>The permissions are represented as <strong>(r, w, x)</strong> for each category, placed in the following order: <strong>owner</strong>, <strong>group</strong>, and <strong>others</strong>.</p>
</li>
<li><p>According to the above statement,</p>
<ul>
<li><p><strong>(-rw-rw-r--)</strong> --&gt; The <strong><em>owner</em></strong> has <strong>read</strong> and <strong>write</strong> permissions, the <strong><em>group</em></strong> has <strong>read</strong> permission, and <strong><em>others</em></strong> have <strong>read</strong> permission as well.</p>
</li>
<li><p><strong>1</strong> --&gt; Indicates the link count number.</p>
</li>
<li><p><strong>myUser</strong> --&gt; Owner of the file</p>
</li>
<li><p><strong>myGroup</strong> --&gt; Group owner of the file</p>
</li>
<li><p><strong>27</strong> --&gt; Size of the file</p>
</li>
<li><p><strong>Jul 14 12.00</strong> --&gt; Timestamps</p>
</li>
<li><p><strong>mainFile</strong> --&gt; Name of the file</p>
</li>
</ul>
</li>
</ul>
<hr />
<h3 id="heading-permissions-and-corresponding-commands-for-files-and-directories"><strong>Permissions and Corresponding Commands for Files and Directories :</strong></h3>
<table><tbody><tr><td><p><strong>Permissions</strong></p></td><td><p><strong>File</strong></p></td><td><p><strong>Directory</strong></p></td></tr><tr><td><p>Read</p></td><td><p>cat</p></td><td><p>ls</p></td></tr><tr><td><p>Write</p></td><td><p>vi/vim/nano/touch</p></td><td><p>mkdir/rmdir</p></td></tr><tr><td><p>Execute</p></td><td><p>sh/run</p></td><td><p>cd</p></td></tr></tbody></table>

<hr />
<h3 id="heading-max-permission-for-files-and-directories"><strong>Max Permission for Files and Directories :</strong></h3>
<p><strong>For Files :</strong></p>
<ul>
<li><p><strong>Ideally</strong>, the max permission for files is "<strong>777</strong>".</p>
</li>
<li><p>However, in practice, it is common to assign "<strong>666</strong>" permissions to <strong>files</strong>.</p>
</li>
<li><p>Assigning "<strong>666</strong>" permissions to files is often <strong>sufficient</strong> for most <strong>regular files</strong>, as they do not need to be <strong>executed</strong> as <strong>programs</strong>.</p>
</li>
<li><p>This permission allows the owner, group, and others to <strong>read</strong> and <strong>modify</strong> the file contents but <strong>does not</strong> <strong>allow</strong> the file to be executed as a program.</p>
</li>
</ul>
<p><strong>For Directories :</strong></p>
<ul>
<li><p>The max permission that can be assigned to directories is "<strong>777</strong>".</p>
</li>
<li><p>However, in practice, it is more common to assign directories permission of "<strong>755</strong>".</p>
</li>
</ul>
<hr />
<h3 id="heading-default-permissions-of-files-and-directories"><strong>Default Permissions of Files and Directories :</strong></h3>
<p><strong>For Files as the root user:</strong></p>
<ul>
<li><p>When the root user creates a file, the default permissions are set to "<strong>644</strong>".</p>
</li>
<li><p>This means the owner has <strong>read</strong> and <strong>write</strong> permissions (rw-).</p>
</li>
<li><p>The group owner of the file has <strong>read</strong> permissions (r--).</p>
</li>
<li><p>Others have <strong>read</strong> permissions (r--).</p>
</li>
</ul>
<p><strong>For Files as a normal user:</strong></p>
<ul>
<li><p>When a normal user creates a file, the default permissions are set to "<strong>664</strong>".</p>
</li>
<li><p>This means the owner has <strong>read</strong> and <strong>write</strong> permissions (rw-).</p>
</li>
<li><p>The group owner of the file has <strong>read</strong> and <strong>write</strong> permissions as well (rw-).</p>
</li>
<li><p>Others have <strong>read</strong> permissions (r--).</p>
</li>
</ul>
<p><strong>For Directories as the root user:</strong></p>
<ul>
<li><p>When the root user creates a directory, the default permissions are set to "<strong>755</strong>".</p>
</li>
<li><p>This means the owner has <strong>read</strong>, <strong>write</strong>, and <strong>execute</strong> permissions (rwx).</p>
</li>
<li><p>The group owner of the file has <strong>read</strong> and <strong>execute</strong> permissions (r-x).</p>
</li>
<li><p>Others have <strong>read</strong> and <strong>execute</strong> permissions (r-x).</p>
</li>
</ul>
<p><strong>For Directories as a normal user:</strong></p>
<ul>
<li><p>When a normal user creates a directory, the default permissions are set to "<strong>775</strong>".</p>
</li>
<li><p>The owner has <strong>read</strong>, <strong>write</strong>, and <strong>execute</strong> permissions (rwx).</p>
</li>
<li><p>The group owner of the file has <strong>read</strong>, <strong>write</strong>, and <strong>execute</strong> permissions as well (rwx).</p>
</li>
<li><p>Others have <strong>read</strong> and <strong>execute</strong> permissions (r-x).</p>
</li>
</ul>
<hr />
<h3 id="heading-to-manually-assign-permissions-to-a-file-in-linux"><strong>To manually assign permissions to a file in Linux:</strong></h3>
<p><strong>COPY</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
chmod &lt;permission&gt; &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
chmod 554 myLinuxFile

<span class="hljs-comment">#Verify...</span>
ls -l myLinuxFile
-r-xr-xr--
</code></pre>
<hr />
<h3 id="heading-to-manually-change-the-user-and-group-of-a-file-in-linux"><strong>To manually change the user and group of a file in Linux:</strong></h3>
<p><strong>COPY</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
chown &lt;testuser&gt;:&lt;testgroup&gt; &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
chown robot:classmate myLinuxFile

<span class="hljs-comment">#Verifying...</span>
ls -l myLinuxFile
-r-xr-xr-- 1 robot classmate 23 Jul 14 12:00 myLinuxFile
</code></pre>
<hr />
<h3 id="heading-to-manually-only-change-the-user-of-a-file-in-linux"><strong>To manually only change the user of a file in Linux:</strong></h3>
<p><strong>COPY</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
sudo chown &lt;testuser&gt; &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
sudo chown robot myLinuxFile

<span class="hljs-comment">#Verifying...</span>
ls -l myLinuxFile
-r-xr-xr-- 1 robot root 23 Jul 14 12:00 myLinuxFile
</code></pre>
<hr />
<h3 id="heading-to-manually-only-change-the-group-of-a-file-in-linux"><strong>To manually only change the group of a file in Linux:</strong></h3>
<p><strong>COPY</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
chgrp &lt;testgroup&gt; &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
chgrp classmate myLinuxFile

<span class="hljs-comment">#Verifying...</span>
ls -l myLinuxFile
-r-xr-xr-- 1 robot classmate 23 Jul 14 12:00 myLinuxFile
</code></pre>
<hr />
<h3 id="heading-umask"><strong>Umask:</strong></h3>
<ul>
<li><p>The <strong>umask</strong> <em>(user file-creation mode mask)</em> is a value that determines the default permissions assigned to newly created files and directories in Linux.</p>
</li>
<li><p>The umask value is <strong>subtracted</strong> from the <strong>max permissions</strong> to determine the resulting <strong>default permissions.</strong></p>
</li>
<li><p>The umask value is usually set in the <strong>shell initialization files</strong> such as <strong>~/.bashrc</strong> which allows it to be applied automatically when a <strong>new shell session</strong> is started.</p>
</li>
<li><p>It can also be modified by using the <strong>umask</strong> <strong>command</strong> in the terminal.</p>
</li>
</ul>
<p><strong>COPY</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
<span class="hljs-built_in">umask</span> &lt;umaskNumber&gt;

<span class="hljs-comment">#Example:</span>
<span class="hljs-built_in">umask</span> 055

<span class="hljs-comment">#Verifying...</span>
<span class="hljs-built_in">umask</span> 
0055
</code></pre>
<hr />
<h3 id="heading-special-permission"><strong>Special Permission:</strong></h3>
<ul>
<li><p>Special Permission refers to additional rights assigned to files and directories beyond the <strong>read</strong>, <strong>write</strong>, and <strong>execute</strong> permissions.</p>
</li>
<li><p>There are three commonly used special permissions: <strong>Sticky bit</strong>, setuid (<strong>SUID</strong>), and setgid (<strong>SGID</strong>).</p>
</li>
</ul>
<h3 id="heading-sticky-bit"><strong>Sticky Bit</strong></h3>
<ul>
<li><p>When the sticky bit is set on a <strong>directory</strong>, only the <strong>owner</strong> of a file within that directory, the <strong>directory owner,</strong> or the <strong>superuser</strong> can <strong>delete</strong> or <strong>rename</strong> the file.</p>
</li>
<li><p><strong>Other users</strong>, even if they have write permissions to the directory, <strong>cannot</strong> delete or rename files that they do not own.</p>
</li>
<li><p><strong>Note</strong>: The <strong>directory</strong> should be provided with full permission along with a sticky bit.</p>
</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment"># Already created a directory with default permission :</span>
[root@localhost tmp]<span class="hljs-comment"># ls -ld myDir</span>
drwxr-xr-x. 2 root root 6 Jul 16 12.00 myDir

<span class="hljs-comment">#Assigning the Sticky Bit (1) and full permission to the directory at once: </span>
[root@localhost tmp]<span class="hljs-comment"># chmod 1777 myDir</span>

<span class="hljs-comment">#Verifying the permission applied...</span>
<span class="hljs-comment">#The sticky bit is represented by the 't' permission bit.</span>
[root@localhost tmp]<span class="hljs-comment"># ls -ld myDir</span>
drwxrwxrwt. 2 root root 6 Jul 16 12.00 myDir
</code></pre>
<ul>
<li>Now create a file "<strong>tryToDelete</strong>" inside the <strong>myDir</strong> directory and <strong>try</strong> to <strong>delete</strong> it using another user who is not the owner of the file, and not a directory owner too, the operation won't permit.</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#Creating a file in myDir</span>
[root@localhost myDir]<span class="hljs-comment"># touch tryToDelete</span>

<span class="hljs-comment">#Writing a small message:</span>
[root@localhost myDir]<span class="hljs-comment"># echo "Hello this is a file created by root user" &gt; tryToDelete</span>

<span class="hljs-comment">#Switch the user:</span>
[root@localhost myDir]<span class="hljs-comment"># su - vnalbalwar</span>

<span class="hljs-comment">#Traversing to the tryToDelete file :</span>
[vnalbalwar@localhost ~]$ <span class="hljs-built_in">cd</span> /tmp/myDir

<span class="hljs-comment">#Trying to delete the file :</span>
[vnalbalwar@localhost myDir]$ rm -rf tryToDelete
rm: cannot remove <span class="hljs-string">'tryToDelete'</span>: Operation not permitted

<span class="hljs-comment">#Deleting using the root user:</span>
[root@localhost myDir]<span class="hljs-comment"># rm -rf tryToDelete</span>
[root@localhost myDir]<span class="hljs-comment"># ls -l</span>
total 0
</code></pre>
<hr />
<h3 id="heading-suid"><strong>SUID</strong></h3>
<ul>
<li><p>A file with a <strong>SUID</strong> set always <strong>executes</strong> as the <strong>user</strong> who <strong>owns</strong> the file, regardless of <strong>any user</strong> executing the command.</p>
</li>
<li><p>The setuid permission is represented by the '<strong>s</strong>' <strong>permission bit</strong> in the <strong>user</strong> execution field.</p>
</li>
<li><p>For example, the 'passwd' command needs to update the password file, which requires <strong>root privileges</strong>.</p>
</li>
<li><p>By setting the setuid bit on the 'passwd' executable, regular users can <strong>execute</strong> it and <strong>change</strong> their passwords.</p>
</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment"># Trying to list the files and directories under root with normal user :</span>
[vnalbalwar@localhost ~]$ ls -l /root/
ls: cannot open directory /root: Permission denied

[vnalbalwar@localhost ~]$ ls -l /usr/bin/ls
-rwxr-xr-x. 1 root root 117608 Jul 21 2020 /usr/bin/ls

<span class="hljs-comment">#Switching to root user and assigning the SUID to /usr/bin/ls :</span>
<span class="hljs-comment"># SUID = 4</span>
<span class="hljs-comment"># You can use this command too : chmod u+s &lt;path&gt;</span>
[root@localhost ~]<span class="hljs-comment"># chmod 4755 /usr/bin/ls</span>
[root@localhost ~]<span class="hljs-comment"># ls -l /usr/bin/ls</span>
-rwsr-xr-x. 1 root root 117608 Jul 21 2020 /usr/bin/ls

<span class="hljs-comment">#Switching back to normal user and now trying to list the /root:</span>
[vnalbalwar@localhost ~]$ ls -l /root/
-rw-------. 1 root root 1907 Jul 5 12.00 anaconda-ks.cfg 

<span class="hljs-comment">#To remove the SUID :</span>
[root@localhost ~]<span class="hljs-comment"># chmod u-s /usr/bin/ls</span>

<span class="hljs-comment">#Verifying...</span>
[root@localhost ~]<span class="hljs-comment"># ls -l /usr/bin/ls</span>
-rwxr-xr-x. 1 root root 117608 Jul 21 2020 /usr/bin/ls
</code></pre>
<hr />
<h3 id="heading-sgid"><strong>SGID:</strong></h3>
<ul>
<li><p>When the SGID permission is set on a <strong>directory</strong>, any <strong>new files</strong> or <strong>directories</strong> created within it <strong>inherit</strong> the <strong>group ownership</strong> of that directory instead of the primary group of the user who created them.</p>
</li>
<li><p>This is useful when multiple users need to collaborate on projects and share files within a common group.</p>
</li>
<li><p>The <strong>SGID</strong> permission is represented by the '<strong>s</strong>' permission bit in the group execution field.</p>
</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#The directory is myCollab and root is owner and group owner of the file:</span>
[root@localhost tmp]<span class="hljs-comment"># ls -l</span>
drwxr-xr-x. 2 root root 6 Jul 16 12.00 myCollab

<span class="hljs-comment">#Creating two files under the myCollab directory:</span>
[root@localhost myCollab]<span class="hljs-comment"># touch file1 file2</span>
[root@localhost myCollab]<span class="hljs-comment"># ls -l </span>
-rw-r--r--. 1 root root 0 Jul 16 12.00 file1
-rw-r--r--. 1 root root 0 Jul 16 12.00 file2

<span class="hljs-comment">#Changing the group owner to testgroup of the myCollab directory:</span>
[root@localhost tmp]<span class="hljs-comment"># chown root:testgroup /tmp/myCollab</span>
[root@localhost tmp]<span class="hljs-comment"># ls -l</span>
drwxr-xr-x. 2 root testgroup 32 Jul 16 12.00 myCollab

<span class="hljs-comment">#Assigning the SGID, 's' indicates the permission bit in group field</span>
[root@localhost tmp]<span class="hljs-comment"># chmod g+s myCollab</span>
[root@localhost tmp]<span class="hljs-comment"># ls -l</span>
drwxr-sr-x. 2 root testgroup 32 Jul 16 12.00 myCollab

 <span class="hljs-comment">#Create a file called file3 in myCollab and check that the group owner is testgroup now:</span>
[root@localhost myCollab]<span class="hljs-comment"># touch file3</span>
[root@localhost myCollab]<span class="hljs-comment"># ls -l file3</span>
-rw-r--r--. 1 root testgroup 0 Jul 16 12.00 file3

<span class="hljs-comment">#How to remove SGID from directory:</span>
[root@localhost tmp]<span class="hljs-comment"># chmod g-s myCollab</span>

<span class="hljs-comment">#Verifying...</span>
[root@localhost tmp]<span class="hljs-comment"># ls -l</span>
drwxr-xr-x. 2 root testgroup 45 Jul 16 12.00 myCollab
</code></pre>
<hr />
]]></content:encoded></item><item><title><![CDATA[Remote Copying Tools, Archiving Tools, Backup & User Management]]></title><description><![CDATA[These are the topics that are covered in today's session.
Pranav Jambare
Remote Copying Tools:
1 . SCP :

SCP stands for secure copy command in Linux.

It is used to copy the files between the servers securely.

It allows the secure transfer of files...]]></description><link>https://viraj-verse.hashnode.dev/remote-copying-tools-archiving-tools-backup-user-management</link><guid isPermaLink="true">https://viraj-verse.hashnode.dev/remote-copying-tools-archiving-tools-backup-user-management</guid><category><![CDATA[Linux]]></category><category><![CDATA[linux kernel]]></category><category><![CDATA[Programming Blogs]]></category><category><![CDATA[linux-commands]]></category><category><![CDATA[#learnwithpra9]]></category><dc:creator><![CDATA[Viraj Nalbalwar]]></dc:creator><pubDate>Tue, 11 Jul 2023 17:04:06 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1689094719431/23841347-38a2-4c81-8dc2-88988382422c.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>These are the topics that are covered in today's session.</p>
<p><a class="user-mention" href="https://hashnode.com/@AutomateMaster">Pranav Jambare</a></p>
<h3 id="heading-remote-copying-tools"><strong>Remote Copying Tools:</strong></h3>
<h3 id="heading-1-scp"><strong>1 . SCP :</strong></h3>
<ul>
<li><p>SCP stands for <strong>secure copy</strong> command in Linux.</p>
</li>
<li><p>It is used to copy the files between the servers <strong>securely</strong>.</p>
</li>
<li><p>It allows the secure transfer of files between the <strong><em>local host</em></strong> and the <strong><em>remote host</em></strong> or between <strong><em>two remote hosts</em></strong>.</p>
</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax :</span>
scp &lt;filename&gt; &lt;remoteuser&gt;@&lt;remoteuserIP&gt;:&lt;destination&gt;
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment">#Example:</span>
scp myLinuxFile root@192.168.100.7:/root
</code></pre>
<h3 id="heading-2-rsync"><strong>2 . RSYNC:</strong></h3>
<ul>
<li><p>RSYNC stands for remote synchronisation command in Linux.</p>
</li>
<li><p>It synchronizes files from a source to a destination.</p>
</li>
<li><p>It is famous for its <strong>delta-transfer algorithm</strong>, which <strong>reduces</strong> the amount of data sent over the network by sending only the <strong>differences</strong> between the source files and the existing files in the destination.</p>
</li>
<li><p>RSYNC finds files that need to be transferred using a <strong>checksum</strong> algorithm that looks for files that have changed in size or in the <strong>last-modified</strong> time.</p>
</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
rsync -av &lt;filename&gt; &lt;remoteuser&gt;@&lt;remoteuserIP&gt;:&lt;destination&gt;
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment">#Example:</span>
rsync -av myLinuxFile root@192.168.100.7:/root
</code></pre>
<h3 id="heading-3-sftp"><strong>3 . SFTP:</strong></h3>
<ul>
<li><p>SFTP stands for <strong>Safe File Transfer Protocol</strong>.</p>
</li>
<li><p>It is a <strong>secure variant</strong> of <strong>FTP</strong>.</p>
</li>
<li><p>It is a part of the <strong>SSH</strong> Protocol and is designed to <strong>securely</strong> transfer files between remote systems via a <strong>network</strong> connection.</p>
</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
sftp &lt;username&gt;@&lt;userIP&gt;
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment">#Example:</span>
sftp linuxUser@192.168.100.7
</code></pre>
<hr />
<h3 id="heading-archiving-tools"><strong>Archiving Tools:</strong></h3>
<ul>
<li><p>Archiving is the process of <strong>combining multiple files</strong> into a <strong>single package</strong> called an <strong>archive</strong>.</p>
</li>
<li><p>This archive can then be easily backed up, or simply kept on your machine as a way to organize your file system.</p>
</li>
</ul>
<h3 id="heading-1-gzip">1 . <strong>gzip</strong></h3>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax : (Compress)</span>
gzip &lt;filename&gt;

<span class="hljs-comment">#Example : </span>
gzip myFile
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax : (Decompress)</span>
gunzip &lt;filename&gt;.gz

<span class="hljs-comment">#Example : </span>
gunzip myFile.gz
</code></pre>
<h3 id="heading-2-xz"><strong>2 . xz</strong></h3>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax: (Compress)</span>
xz &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
xz myFile
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax: (Decompress)</span>
unxz &lt;filename&gt;.xz

<span class="hljs-comment">#Example:</span>
unxz myFile.xz
</code></pre>
<h3 id="heading-3-bzip2"><strong>3 . bzip2</strong></h3>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax: (Compress)</span>
bzip2 &lt;filename&gt;

<span class="hljs-comment">#Example:</span>
bzip2 myFile
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax: (Decompress)</span>
bzip2 &lt;filename&gt;.bz2

<span class="hljs-comment">#Example:</span>
bzip2 myFile.bz2
</code></pre>
<hr />
<h3 id="heading-backup"><strong>Backup:</strong></h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1689087829751/8c63f4dd-7f5c-42ba-b610-dff65e5b9127.webp" alt="Regular files being added to an archive with tar and then compressed with gzip." class="image--center mx-auto" /></p>
<p>Fig. Regular files being added to an archive with tar and then compressed with gzip.</p>
<ul>
<li><p>The tar utility is also able to compress an archive via a compression tool.</p>
</li>
<li><p>To create an archive file :</p>
</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
tar -cvzf &lt;destn.backup&gt; &lt;sourcefile&gt;

<span class="hljs-comment">#Example:</span>
tar -cvzf myLinuxFile.backup file1 file2 file3
</code></pre>
<ul>
<li>To extract an archive file:</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment">#Syntax:</span>
tar -xvf &lt;destn.backup&gt;

<span class="hljs-comment">#Example:</span>
tar -xvf myLinuxFile.backup
</code></pre>
<hr />
<h3 id="heading-user-management"><strong>User Management:</strong></h3>
<ul>
<li><p>A user is an entity, that can <strong>manipulate</strong> files and <strong>perform</strong> several other operations.</p>
</li>
<li><p>Each user is assigned an ID that is unique for each user in the operating system.</p>
</li>
<li><p>The <strong>ID 0</strong> is assigned to the <strong>root user</strong> and the <strong>IDs 1 to 999</strong> are assigned to the system users, hence the ids for the local user begin from 1000 onwards. </p>
</li>
</ul>
<p><strong>1 . Adding the User :</strong></p>
<ul>
<li><p>The command "<strong><em>useradd</em></strong>" or "<strong><em>adduser</em></strong>" can be used to create a new user in Linux also, the sudo permissions are required to perform this command.</p>
<pre><code class="lang-bash">  <span class="hljs-comment">#Creating a User:</span>
  root@myLinux:~<span class="hljs-comment"># useradd testuser</span>
  <span class="hljs-comment">#OR</span>
  root@myLinux:~<span class="hljs-comment"># adduser testuser</span>
</code></pre>
</li>
</ul>
<p><strong>2 . Verifying the User:</strong></p>
<pre><code class="lang-bash">root@myLinux:~<span class="hljs-comment"># id testuser</span>
uid=1001(testuser) gid=1001(testuser) groups=1001(testuser)
</code></pre>
<p><strong>3 . Deleting the User:</strong></p>
<pre><code class="lang-bash">root@myLinux:~<span class="hljs-comment"># userdel testuser</span>
</code></pre>
<p><strong>4 . Managing the password policy:</strong></p>
<p><strong>Fields of /etc/password file:</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment">#The sudo permissions are required to perform this command</span>
root@myLinux:~<span class="hljs-comment"># cat /etc/passwd|tail -1</span>
testuser:x:1001:1001::/home/testuser:/bin/sh
</code></pre>
<p>Where,</p>
<blockquote>
<p>testuser --&gt; <strong>Name of user</strong></p>
<p>x --&gt; <strong>Encrpyted password</strong></p>
<p>1001 --&gt; <strong>User id</strong></p>
<p>1001 --&gt; <strong>Group id</strong></p>
<p>:: --&gt; <strong>Nickname (Con-name)</strong></p>
<p>/home/testuser --&gt; <strong><em>Home directory of the user</em></strong></p>
<p><em>/bin/bash</em> <em>--&gt;</em> <strong><em>Default shell of user</em></strong></p>
</blockquote>
<hr />
<p><strong>Setting the password :</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment">#The sudo permissions are required to perform this command</span>
root@myLinux:~<span class="hljs-comment"># passwd testuser</span>
<span class="hljs-comment">#Next...</span>
New password: 123 
Retype new password: 123
passwd: password updated successfully
</code></pre>
<hr />
<p><strong>Changing the password policy:</strong></p>
<pre><code class="lang-bash">root@myLinux:~<span class="hljs-comment"># chage -M 2 -m 5000 -W 4 -I 12 -E 2024-12-2</span>
</code></pre>
<p>Where,</p>
<blockquote>
<p>-M --&gt; maxdays password change date</p>
<p>-m --&gt; mindays password change date</p>
<p>-W --&gt; warning</p>
<p>-I --&gt; Inactivity</p>
<p>-E --&gt; Account Expiry date</p>
</blockquote>
<hr />
<p><strong>5 . Change / Restrict the User:</strong></p>
<p><strong>Give "No Login" to the User:</strong></p>
<pre><code class="lang-bash">root@myLinux:~<span class="hljs-comment"># usermod testuser -s /sbin/nologin</span>

<span class="hljs-comment">#Verifying...</span>
root@myLinux:~<span class="hljs-comment"># su - testuser</span>
Cannot change directory to /home/testuser:   
No such file or directory
This account is currently not available.
</code></pre>
<p><strong>To revert the changes to get a login:</strong></p>
<pre><code class="lang-bash">root@myLinux:~<span class="hljs-comment"># usermod testuser -s /bin/sh</span>

<span class="hljs-comment">#Verifying...</span>
root@myLinux:~<span class="hljs-comment"># su - testuser</span>
Last Login : .....
<span class="hljs-variable">$whoami</span>
testuser
</code></pre>
<hr />
<p><strong>6 . Lock and Unlock User:</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment"># To Lock the user:</span>
root@myLinux:~<span class="hljs-comment"># usermod -L testuser</span>

<span class="hljs-comment"># To Unlock the user:</span>
root@myLinux:~<span class="hljs-comment"># usermod -U testuser</span>
</code></pre>
<hr />
<p><strong>7 . Adding Group:</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment">#The sudo permissions are required to perform this command</span>
root@myLinux:~<span class="hljs-comment"># groupadd testgroup</span>

<span class="hljs-comment">#Verifying the group...</span>
root@myLinux:~<span class="hljs-comment"># cat /etc/group|tail -1   </span>
testgroup:x:1002:
</code></pre>
<hr />
<p><strong>8 . Adding a user to a group:</strong></p>
<pre><code class="lang-bash">root@myLinux:~<span class="hljs-comment"># usermod -G testgroup testuser </span>

<span class="hljs-comment">#Verifying...</span>
root@myLinux:~<span class="hljs-comment"># id testuser</span>
uid=1001(testuser) gid=1001(testuser) groups=1001(testuser),1002(testgroup)
</code></pre>
<hr />
<p><strong>9 . Deleting a group:</strong></p>
<pre><code class="lang-bash">root@myLinux:~<span class="hljs-comment"># groupdel testgroup</span>

<span class="hljs-comment">#Verifying...</span>
root@myLinux:~<span class="hljs-comment"># id testuser</span>
uid=1001(testuser) gid=1001(testuser) groups=1001(testuser)
</code></pre>
<hr />
<p><strong>10 . Change the user-id of the user:</strong></p>
<pre><code class="lang-bash">root@myLinux:~<span class="hljs-comment"># usermod -u 1005 testuser</span>

<span class="hljs-comment">#Verifying...</span>
root@myLinux:~<span class="hljs-comment"># id testuser</span>
uid=1005(testuser) gid=1001(testuser) groups=1001(testuser)
</code></pre>
<hr />
]]></content:encoded></item><item><title><![CDATA[Embracing into the World of Linux]]></title><description><![CDATA[Hello everyone, I am Viraj Nalbalwar. I attended the first workshop on Linux at DBATU, Lonere today. It was conducted by our alumnus, Pranav Jambare, who is currently working as a DevOps Engineer at TCS.
We started with Linux Introduction:
Operating ...]]></description><link>https://viraj-verse.hashnode.dev/embracing-into-the-world-of-linux</link><guid isPermaLink="true">https://viraj-verse.hashnode.dev/embracing-into-the-world-of-linux</guid><category><![CDATA[Linux]]></category><category><![CDATA[linux for beginners]]></category><category><![CDATA[Ubuntu]]></category><category><![CDATA[programmer]]></category><category><![CDATA[#learnwithpra9]]></category><dc:creator><![CDATA[Viraj Nalbalwar]]></dc:creator><pubDate>Mon, 10 Jul 2023 13:09:50 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1688994039105/bb093224-57b9-4ef0-a9ba-a1b33e23c413.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello everyone, I am Viraj Nalbalwar. I attended the first workshop on Linux at DBATU, Lonere today. It was conducted by our alumnus, Pranav Jambare, who is currently working as a DevOps Engineer at TCS.</p>
<p>We started with Linux Introduction:</p>
<h3 id="heading-operating-system"><strong>Operating System</strong></h3>
<ul>
<li><p>OS is an interface between computer users and hardware.</p>
</li>
<li><p>Manages all other application programs on a computer.</p>
</li>
<li><p>Performs all the basic tasks like file management, memory management, process management, and handling inputs and outputs.</p>
</li>
<li><p>E.g. Windows, Fedora, Mac, Ubuntu, Redhat, Suse, etc.</p>
</li>
</ul>
<h3 id="heading-why-choose-linux"><strong>Why choose Linux?</strong></h3>
<ul>
<li><p>Free and Reliable.</p>
</li>
<li><p>Open Source and Secure.</p>
</li>
<li><p>Privacy and Updates.</p>
</li>
<li><p>Can be customized and has better community support.</p>
</li>
</ul>
<h3 id="heading-kernel"><strong>Kernel</strong></h3>
<ul>
<li><p>The kernel is the heart of any operating system.</p>
</li>
<li><p>Acts as a middleware (interpreter) between shell and hardware.</p>
</li>
<li><p>It has all the code required for OS to execute.</p>
</li>
<li><p>If the kernel crashes, OS crashes too.</p>
</li>
</ul>
<h3 id="heading-shell"><strong>Shell</strong></h3>
<ul>
<li><p>It is a terminal and allows a user to give commands to the kernel.</p>
</li>
<li><p>Acts as an interface between a user and the kernel.</p>
</li>
</ul>
<hr />
<h3 id="heading-yanking"><strong>Yanking</strong></h3>
<p>In the terminal, you can <strong>cut</strong>, <strong>copy</strong> and <strong>paste</strong> a line with the following commands.</p>
<p>E.g.</p>
<ul>
<li><p><strong>yy</strong> - Used to copy a line. Move the cursor to the line you want to copy and then press yy.</p>
</li>
<li><p><strong>p</strong> - Paste a copied or cut line after the current line.</p>
</li>
<li><p><strong>dd</strong> (<strong>cut)</strong> - Deletes current line completely.</p>
</li>
</ul>
<p>Many commands, such as <strong>cc</strong>, <strong>gg</strong>, <strong>G</strong>, <strong>:!&lt;command&gt;</strong>, and <strong>:set nu,</strong> can also be executed in the <strong>Vi/Vim</strong> editor.</p>
<hr />
<h3 id="heading-redirection"><strong>Redirection</strong></h3>
<p>Imagine you have a command that produces some output on the screen. With <strong>redirection</strong>, you can choose to <strong>send</strong> that <strong>output</strong> or <strong>error</strong> to a <strong>file</strong> instead of displaying it on the screen. This way, you can save the output or <strong>error</strong> for later use or <strong>analyze</strong> it more conveniently.</p>
<p>Commands :</p>
<ul>
<li>Used to search for directories owned by a specific user</li>
</ul>
<pre><code class="lang-plaintext">find / -user &lt;username&gt;
</code></pre>
<ul>
<li>With the addition of "<strong>2&gt; &lt;errorfile&gt;</strong>", any error messages generated by the "<strong>find</strong>" command during the search process will be <strong><em>redirected</em></strong> to the specific "<strong>&lt;errorfile&gt;</strong>". This way, you can store the error messages separately while the regular output is displayed on the screen.</li>
</ul>
<pre><code class="lang-bash">find / -user &lt;username&gt; 2&gt; &lt;errorfile&gt;
</code></pre>
<ul>
<li>With the addition of "<strong>&gt; &lt;outputfile&gt;</strong>", outputs generated by the "<strong>find</strong>" command during the search process will be <strong><em>redirected</em></strong> to the specific "<strong>&lt;outputfile&gt;</strong>". This way, you can store the outputs separately while only the errors will be displayed on the screen.</li>
</ul>
<pre><code class="lang-bash">find / -user &lt;username&gt;&gt; &lt;outputfile&gt;
</code></pre>
<ul>
<li>"<strong>find</strong>" will search for directories owned by the specified user, and the output will be redirected to the "&lt;<strong>outputfile</strong>&gt;". Any errors generated during the search will be redirected to the "&lt;<strong>errorfile</strong>&gt;".</li>
</ul>
<pre><code class="lang-bash">find / -user &lt;username&gt;&gt; &lt;outputfile&gt; 2&gt; &lt;errorfile&gt;
</code></pre>
<ul>
<li>Both the regular output and any error messages generated during the search will be removed and not displayed or saved anywhere.</li>
</ul>
<pre><code class="lang-bash">find / -user &lt;username&gt; &amp;&gt; /dev/null
</code></pre>
<ul>
<li>This command is used to search directories owned by a specific user and save the output to both the terminal and a file.</li>
</ul>
<pre><code class="lang-bash">find / -user &lt;username&gt; | tee &lt;filename&gt;
</code></pre>
<hr />
<h3 id="heading-modes"><strong>Modes</strong></h3>
<ul>
<li><p>ESC Mode</p>
</li>
<li><p>Insert Mode</p>
</li>
<li><p>wq! (Save and Quit)</p>
</li>
<li><p>v (Visual Mode)</p>
</li>
</ul>
<hr />
<h3 id="heading-finally"><strong>Finally...</strong></h3>
<p>I enjoyed the session conducted by <a class="user-mention" href="https://hashnode.com/@AutomateMaster">Pranav Jambare</a> . Just remember to constantly put in your hard work and believe it will be worth it one day!</p>
]]></content:encoded></item></channel></rss>