<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ unix - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ unix - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Sun, 24 May 2026 22:25:16 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/unix/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Manage Directory-Scoped Variables with direnv in POSIX Systems ]]>
                </title>
                <description>
                    <![CDATA[ By Otavio Ehrenberger A common practice in software projects is to keep certain information separated but accessible from the codebase which uses it. Developers usually do this with secrets such as passwords or private keys, or with user or context-s... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-manage-directory-scoped-envs-with-direnv-in-posix-systems/</link>
                <guid isPermaLink="false">66d851f3a2a6d73be8613879</guid>
                
                    <category>
                        <![CDATA[ Productivity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ unix ]]>
                    </category>
                
                    <category>
                        <![CDATA[ variables ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 22 Nov 2021 21:39:20 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/11/pexels-aleksejs-bergmanis-681335.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Otavio Ehrenberger</p>
<p>A common practice in software projects is to keep certain information separated but accessible from the codebase which uses it. Developers usually do this with secrets such as passwords or private keys, or with user or context-specific info pieces. </p>
<p>But managing environment variables can be a pain. There are a number of solutions to ease that pain, and there are even built-in ones such as <a target="_blank" href="https://www.baeldung.com/linux/bashrc-vs-bash-profile-vs-profile">bash_profile</a>.</p>
<p>One solution I've discovered recently and found particularly convenient is <a target="_blank" href="https://github.com/direnv/direnv">direnv</a>. It's a shell extension which lets you define environment variables scoped by directory. </p>
<p>After installing and hooking the extension to your shell, <code>direnv</code> will execute every time you change directories, looking for an <code>.envrc</code> file in the same or in a superior directory tree level. It will then load the defined variables to the current environment, and unload them if it ceases to detect the same <code>.envrc</code>.</p>
<p>Note that <code>direnv</code> will load the first detected <code>.envrc</code> file, which means that <em>the environment will</em> <strong>not</strong> <em>inherit values from a</em> <code>.envrc</code> <em>in a parent directory</em>.</p>
<p>It is also important to keep in mind that the environment variables <em>will only be loaded to your shell session once you move to a directory affected by a</em> <code>.envrc</code> <em>file</em>. So if you try something like running a script which loads an environment defined in a directory below your current level, the variables won't be accessible.</p>
<h2 id="heading-how-to-install-direnv">How to Install <code>direnv</code></h2>
<p>Here's a <a target="_blank" href="https://direnv.net/docs/installation.html">list of supported systems</a>. It is very likely that your UNIX-based system's main open source package manager has it available. </p>
<p>Suppose we are on Debian, we can install <code>direnv</code> by running the standard external package install command in the terminal:</p>
<pre><code class="lang-bash">sudo apt-get install direnv
</code></pre>
<h2 id="heading-how-to-setup-direnv">How to Setup <code>direnv</code></h2>
<p>After you install it, you need to hook <code>direnv</code> to your shell. If you're using bash, you can do this by appending this line to the end of your shell startup config file:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> <span class="hljs-string">'eval "$(direnv hook bash)"'</span> &gt;&gt; ~/.bashrc
</code></pre>
<p>It's almost the same for ZShell:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> <span class="hljs-string">'eval "$(direnv hook zsh)"'</span> &gt;&gt; ~/.zshrc
</code></pre>
<p>Direnv also supports FISH, TCSH, and Elvish. <a target="_blank" href="https://direnv.net/docs/hook.html">Here are the hooking instructions for each supported shell</a>.</p>
<h2 id="heading-how-to-use-direnv">How to Use <code>direnv</code></h2>
<p>Now we must create an <code>.envrc</code> file for the directory we would like to scope the environment variables to.</p>
<p>Say we create it for the directory <code>~/project</code>.</p>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> <span class="hljs-built_in">export</span> FOO=<span class="hljs-string">'I love Linux!'</span> &gt;&gt; ~/project/.envrc
</code></pre>
<p>You will then receive a warning that the current <code>.envrc</code> wasn't read. <code>direnv</code> will block loading <code>.envrc</code> every time it detects changes which were not explicitly allowed. So now run:</p>
<pre><code class="lang-bash">direnv allow ~/project
</code></pre>
<p>and voilà!, you now have a directory-scoped environment.</p>
<p>Remember when I told you that '<code>direnv</code> will block loading <code>.envrc</code> every time it detects changes which were not explicitly allowed'? This isn't limited to newly introduced changes – the whole file will be unauthorized. So when you do this:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> <span class="hljs-built_in">export</span> BAR=<span class="hljs-string">'It is actually called GNU/Linux!'</span> &gt;&gt; ~/project/.envrc
</code></pre>
<p>you will have to run <code>direnv allow ~/project</code> again, even to access <code>$FOO</code>. Kinda boring, but biased towards safety.</p>
<p>Every time an <code>.envrc</code> is loaded, direnv will output a message with the file path and also the names of the variables loaded, so you don't need to worry about forgetting your setup. It will also tell you whenever an environment was unloaded.</p>
<h3 id="heading-thanks-for-reading">Thanks for reading!</h3>
<p>That's it! It's pretty straightforward, and I hope you find it as convenient as I did.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ The Linux AWK Command – Linux and Unix Usage Syntax Examples ]]>
                </title>
                <description>
                    <![CDATA[ In this beginner-friendly guide, you'll learn the very basics of the awk command. You'll also see some of the ways you can use it when dealing with text. Let's get started! What is the awk command? awk is a scripting language, and it is helpful when ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/the-linux-awk-command-linux-and-unix-usage-syntax-examples/</link>
                <guid isPermaLink="false">66b1e4c20938e6258a76bbe1</guid>
                
                    <category>
                        <![CDATA[ Linux ]]>
                    </category>
                
                    <category>
                        <![CDATA[ unix ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Dionysia Lemonaki ]]>
                </dc:creator>
                <pubDate>Tue, 12 Oct 2021 15:34:47 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/10/florian-klauer-mk7D-4UCfmg-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In this beginner-friendly guide, you'll learn the very basics of the <code>awk</code> command. You'll also see some of the ways you can use it when dealing with text.</p>
<p>Let's get started!</p>
<h2 id="heading-what-is-the-awk-command">What is the <code>awk</code> command?</h2>
<p><code>awk</code> is a scripting language, and it is helpful when working in the command line. It's also a widely used command for text processing.</p>
<p>When using <code>awk</code>, you are able to select data – one or more pieces of individual text – based on a pattern you provide.</p>
<p>For example, some of the operations you can do with <code>awk</code> are searching for a specific word or pattern in a piece of text given, or even select a certain line or a certain column in a file you provide.</p>
<h3 id="heading-the-basic-syntax-of-the-awk-command">The Basic Syntax of the <code>awk</code> command</h3>
<p>In its simplest form, the <code>awk</code> command is followed by a set of single quotation marks and a set of curly braces, with the name of the file you want to search through mentioned last. </p>
<p>It looks something like this:</p>
<pre><code>awk <span class="hljs-string">'{action}'</span> your_file_name.txt
</code></pre><p>When you want to search for text that has a specific pattern or you're looking for a specific word in the text, the command would look something like this:</p>
<pre><code>awk <span class="hljs-string">'/regex pattern/{action}'</span> your_file_name.txt
</code></pre><h3 id="heading-how-to-create-a-sample-file">How to create a sample file</h3>
<p>To create a file in the command line, you use the <code>touch</code> command. 
For example: <code>touch filename.txt</code> where <code>filename</code>, is the name of your file.</p>
<p>You can then use the <code>open</code> command (<code>open filename.txt</code>), and a word processor program like TextEdit will open where you can add the contents of the file.</p>
<p>So, say you have a text file, <code>information.txt</code>, that contains data separated into different columns. </p>
<p>The file contents could look something like this:</p>
<pre><code>fristName       lastName        age     city       ID

Thomas          Shelby          <span class="hljs-number">30</span>      Rio        <span class="hljs-number">400</span>
Omega           Night           <span class="hljs-number">45</span>      Ontario    <span class="hljs-number">600</span>
Wood            Tinker          <span class="hljs-number">54</span>      Lisbon     N/A
Giorgos         Georgiou        <span class="hljs-number">35</span>      London     <span class="hljs-number">300</span>
Timmy           Turner          <span class="hljs-number">32</span>      Berlin     N/A
</code></pre><p>In my example, there is one column for <code>firstName</code>, <code>lastName</code>, <code>age</code>, <code>city</code>, and <code>ID</code>.</p>
<p>At any time, you can view the output of the contents of your file by typing <code>cat text_file</code>, where <code>text_file</code> is the name of your file.</p>
<h3 id="heading-how-to-print-all-the-contents-of-the-file-using-awk">How to print all the contents of the file using <code>awk</code></h3>
<p>To print <em>all</em> the contents of a file, the action you specify inside the curly braces is <code>print $0</code>.</p>
<p>This will work in exactly the same way as the <code>cat</code> command mentioned previously.</p>
<pre><code class="lang-shell">awk '{print $0}' information.txt
</code></pre>
<p>Ouptut:</p>
<pre><code>fristName       lastName        age     city       ID

Thomas          Shelby          <span class="hljs-number">30</span>      Rio        <span class="hljs-number">400</span>
Omega           Night           <span class="hljs-number">45</span>      Ontario    <span class="hljs-number">600</span>
Wood            Tinker          <span class="hljs-number">54</span>      Lisbon     N/A
Giorgos         Georgiou        <span class="hljs-number">35</span>      London     <span class="hljs-number">300</span>
Timmy           Turner          <span class="hljs-number">32</span>      Berlin     N/A
</code></pre><p>If you would like each line to have a line-number count, you would use the <code>NR</code> built-in variable:</p>
<pre><code class="lang-shell">awk '{print NR,$0}' information.txt
</code></pre>
<pre><code><span class="hljs-number">1</span> fristName     lastName        age     city       ID
<span class="hljs-number">2</span> 
<span class="hljs-number">3</span> Thomas        Shelby          <span class="hljs-number">30</span>      Rio        <span class="hljs-number">400</span>
<span class="hljs-number">4</span> Omega         Night           <span class="hljs-number">45</span>      Ontario    <span class="hljs-number">600</span>
<span class="hljs-number">5</span> Wood          Tinker          <span class="hljs-number">54</span>      Lisbon     N/A
<span class="hljs-number">6</span> Giorgos       Georgiou        <span class="hljs-number">35</span>      London     <span class="hljs-number">300</span>
<span class="hljs-number">7</span> Timmy         Turner          <span class="hljs-number">32</span>      Berlin     N/A
</code></pre><h3 id="heading-how-to-print-specific-columns-using-awk">How to print specific columns using <code>awk</code></h3>
<p>When using <code>awk</code>, you can specify certain columns you want printed.</p>
<p>To have the first column printed, you use the command:</p>
<pre><code class="lang-shell">awk '{print $1}' information.txt
</code></pre>
<p>Ouput:</p>
<pre><code>Thomas
Omega
Wood
Giorgos
Timmy
</code></pre><p>The <code>$1</code> stands for the first field, in this case the first column.</p>
<p>To print the second column,you would use <code>$2</code>:</p>
<pre><code class="lang-shell">awk '{print $2}' information.txt
</code></pre>
<p>Output:</p>
<pre><code>lastName

Shelby
Night
Tinker
Georgiou
Turner
</code></pre><p>The way <code>awk</code> determines where each column starts and ends is with a space, by default.</p>
<p>To print more than one column, for example the first and forth columns, you would do:</p>
<pre><code class="lang-shell">awk '{print $1, $4}' information.txt
</code></pre>
<p>Ouput:</p>
<pre><code>fristName city

Thomas    Rio
Omega     Ontario
Wood      Lisbon
Giorgos   London
Timmy     Berlin
</code></pre><p>The <code>$1</code> represents the first input field (first column), and the <code>$4</code> represents the forth. You separate them with a comma, <code>$1,$4</code>, so the output has a space and is more readable.</p>
<p>To print the last field (the last column), you can also use <code>$NF</code> which represents the <em>last</em> field in a record:</p>
<pre><code class="lang-shell">awk '{print $NF}' information.txt
</code></pre>
<p>Output:</p>
<pre><code>ID

<span class="hljs-number">400</span>
<span class="hljs-number">600</span>
N/A
<span class="hljs-number">300</span>
N/A
</code></pre><h3 id="heading-how-to-print-specific-lines-of-a-column">How to print specific lines of a column</h3>
<p>You can also specify the line you want printed from your chosen column:</p>
<pre><code class="lang-shell">awk '{print $1}' information.txt | head -1
</code></pre>
<p>Ouput:</p>
<pre><code>FirstName
</code></pre><p>Let's break that command down. <code>awk '{print $1}' information.txt</code> prints the first column. Then the output of that command (which you saw earlier on) is <em>piped</em>, using the pipe symbol <code>|</code>, to the head command, where its <code>-1</code> argument selects the first line of the column.</p>
<p>If you wanted two lines printed, you'd do:</p>
<pre><code class="lang-shell">awk '{print $1}' information.txt | head -2
</code></pre>
<p>Output:</p>
<pre><code>FirstName
Dionysia
</code></pre><h3 id="heading-how-to-print-out-lines-with-a-specific-pattern-in-awk">How to print out lines with a specific pattern in <code>awk</code></h3>
<p>You can print a line that <strong>starts</strong> with a specific letter.</p>
<p>For example:</p>
<pre><code class="lang-shell">awk '/^O/' information.txt
</code></pre>
<p>Output:</p>
<pre><code>Omega           Night           <span class="hljs-number">45</span>      Ontario    <span class="hljs-number">600</span>
</code></pre><p>That command selects any line with text that <em>starts</em> with an <code>O</code>. </p>
<p>You use the up arrow symbol (<code>^</code>) first, which indicates the beginning of a line, and then the letter you want a line to start with.</p>
<p>You can also print a line that <strong>ends</strong> in a specific pattern:</p>
<pre><code class="lang-shell">awk '/0$/' information.txt
</code></pre>
<p>Output:</p>
<pre><code>Thomas          Shelby          <span class="hljs-number">30</span>      Rio        <span class="hljs-number">400</span>
Omega           Night           <span class="hljs-number">45</span>      Ontario    <span class="hljs-number">600</span>
Giorgos         Georgiou        <span class="hljs-number">35</span>      London     <span class="hljs-number">300</span>
</code></pre><p>This prints out the lines that end in a <code>0</code> – the <code>$</code> symbol is used after a character to siginify how a line will end.</p>
<p>That command could also be changed to:</p>
<pre><code class="lang-shell">awk '! /0$/' information.txt
</code></pre>
<p>The <code>!</code> is used as a <code>NOT</code>, so in this case it selects the lines that DON'T end in a <code>0</code>.</p>
<pre><code>fristName       lastName        age     city       ID

Wood            Tinker          <span class="hljs-number">54</span>      Lisbon     N/A
Timmy           Turner          <span class="hljs-number">32</span>      Berlin     N/A
</code></pre><h4 id="heading-how-to-use-regular-expressions-in-awk">How to use regular expressions in <code>awk</code></h4>
<p>To output words that contain certain letters and print out words that match a pattern you specify, you again use the slashes, <code>//</code>, shown previously.</p>
<p>If you want to look for words containing <code>on</code>, you'd do:</p>
<pre><code class="lang-shell">awk ' /io/{print $0}' information.txt
</code></pre>
<p>Output:</p>
<pre><code>Thomas          Shelby          <span class="hljs-number">30</span>      Rio        <span class="hljs-number">400</span>
Omega           Night           <span class="hljs-number">45</span>      Ontario    <span class="hljs-number">600</span>
Giorgos         Georgiou        <span class="hljs-number">35</span>      London     <span class="hljs-number">300</span>
</code></pre><p>This matches all entries that contain <code>io</code>.</p>
<p>Say you had an extra column – a <code>department</code> column:</p>
<pre><code>fristName       lastName        age     city       ID   department

Thomas          Shelby          <span class="hljs-number">30</span>      Rio        <span class="hljs-number">400</span>  IT
Omega           Night           <span class="hljs-number">45</span>      Ontario    <span class="hljs-number">600</span>  Design
Wood            Tinker          <span class="hljs-number">54</span>      Lisbon     N/A  IT
Giorgos         Georgiou        <span class="hljs-number">35</span>      London     <span class="hljs-number">300</span>  Data
Timmy           Turner          <span class="hljs-number">32</span>      Berlin     N/A  Engineering
</code></pre><p>To find all the information of people working in <code>IT</code>, you would need to speficy the string you're searching for between the slashes, <code>//</code>:</p>
<pre><code class="lang-shell">awk '/IT/' information.txt
</code></pre>
<p>Output:</p>
<pre><code>Thomas          Shelby          <span class="hljs-number">30</span>      Rio        <span class="hljs-number">400</span>  IT
Wood            Tinker          <span class="hljs-number">54</span>      Lisbon     N/A  IT
</code></pre><p>What if you wanted to see only the first and last names of the people working in <code>IT</code>?</p>
<p>You can specify the column like such:</p>
<pre><code class="lang-shell">awk '/IT/{print $1, $2}' information.txt
</code></pre>
<p>Output:</p>
<pre><code>Thomas Shelby
Wood   Tinker
</code></pre><p>This will only display the first and second columns where <code>IT</code> appears, instead of presenting all fields.</p>
<p>When searching for words with a specific pattern, there may be times when you'll need to use an escape character, like such:</p>
<pre><code class="lang-shell">awk '/N\/A$/' information.txt
</code></pre>
<p>Output:</p>
<pre><code class="lang-shell">Wood            Tinker          54      Lisbon     N/A
Timmy           Turner          32      Berlin     N/A
</code></pre>
<p>I wanted to find lines that end with the pattern <code>N/A</code>. </p>
<p>So, when searching between the <code>' // '</code> like shown so far, I had to use an escape character (<code>\</code>) between <code>N/A</code>, otherwise I would've gotten an error.</p>
<h3 id="heading-how-to-use-comparisson-operators-in-awk">How to use comparisson operators in <code>awk</code></h3>
<p>If, for example, you wanted to find all the information of employees that were under the age of <code>40</code>, you would use the <code>&lt;</code> comparisson operator like so:</p>
<pre><code class="lang-shell">awk '$3 &lt;  40 { print $0 }' information.txt
</code></pre>
<p>Output:</p>
<pre><code>Thomas          Shelby          <span class="hljs-number">30</span>      Rio        <span class="hljs-number">400</span>
Giorgos         Georgiou        <span class="hljs-number">35</span>      London     <span class="hljs-number">300</span>
Timmy           Turner          <span class="hljs-number">32</span>      Berlin     N/A
</code></pre><p>The output shows only the information of people under 40.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>And there you have it! You now know the absolute basics to start working with <code>awk</code> and manipulate text data.</p>
<p>To learn more about Linux, freeCodeCamp has a wide variety of learning materials available. </p>
<p>Here are a couple of them get you started:</p>
<ul>
<li><a target="_blank" href="https://www.youtube.com/watch?v=0Qnwqe2P3eY">Linux Basics - Hands-On Workshop</a></li>
<li><a target="_blank" href="https://www.youtube.com/watch?v=lZAoFs75_cs&amp;t=77s">Linux for Ethical Hackers (Kali Linux Tutorial)</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/the-linux-commands-handbook/">The Linux Command Handbook</a></li>
</ul>
<p>Thanks for reading and happy learning 😊</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is an OS? Operating System Definition for Beginners ]]>
                </title>
                <description>
                    <![CDATA[ Developers have long debated what is the best operating system.  Now, if you are active on social media platforms and developer forums you might have come across Twitter polls and endless discussions on platforms like Reddit, StackOverflow, and other... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-an-os-operating-system-definition-for-beginners/</link>
                <guid isPermaLink="false">66b8dc17041b2e96339f90f9</guid>
                
                    <category>
                        <![CDATA[ beginners guide ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Computer Science ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Computers ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Linux ]]>
                    </category>
                
                    <category>
                        <![CDATA[ macOS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ unix ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Windows ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Hillary Nyakundi ]]>
                </dc:creator>
                <pubDate>Tue, 31 Aug 2021 16:50:03 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/08/uide-to-writting-a-good-readme-file--6-.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Developers have long debated what is the best operating system. </p>
<p>Now, if you are active on social media platforms and developer forums you might have come across Twitter polls and endless discussions on platforms like Reddit, StackOverflow, and others. We haven't come up with a solid answer yet because everybody has their own opinion.</p>
<p>I will promise you one thing here – we won't be answering this question in this article, as trying to answer this question is similar to answering <em>which is the best laptop for a developer to use</em> – we all have different preferencese, right? </p>
<p>But what this article will do is discuss questions like:</p>
<ul>
<li>What is an operating system?</li>
<li>The history of operating systems</li>
<li>How an operating system works</li>
<li>Types and examples of operating systems</li>
<li>Functions of an operating system</li>
<li>Why you need an operating system</li>
</ul>
<p>By answering these questions hopefully you will be in a position to choose the right operating system for your needs. You'll also understand the basics of how an operating system works, and that will be the best OS for you as a developer.</p>
<p>Let's get started:</p>
<h2 id="heading-what-is-an-operating-system">What is an Operating System?</h2>
<p>The recent advancements in technologies, where every gadget is considered a smart device has really revolutionized the world. Almost everyone has access to this devices be it mobile phones, tablets, laptops, smart watches or even your personal computer at home. Also to add to the list the huge rising number of the modern vehicles.</p>
<p>What all the above mentioned have in common is, they use an operating system to enable their functionality for you to achieve a certain task. Despite all this amazing being owned by us, very few of us get to understand how the OS that makes it possible to achieve different tasks is structured.</p>
<p>With this understanding we can describe an Operating System(<em>OS</em>) as a software that manages computer hardware and software resources and provides common services for computer programs.</p>
<p>In simple English we can say an OS is an interface between the user and the machine that makes it easy for the user to achieve different tasks with ease.</p>
<p>Now you have an understanding of what an OS is and also a slight idea of what it does, So! how did it all come into existence, where did it all begin? Let's have a look at it's history</p>
<h2 id="heading-history-of-operating-systems">History of Operating Systems</h2>
<p>It all began back in the 1950s, when computer could only handle one program at a go. During this period users directly interacted with the computer hardware. For a program to be executed it was loaded in an input device like a card reader before execution could begin, and incase of an error during execution the registers and main memory had to be inspected to determine the cause of the error. </p>
<p>When the first operating system was developed by General Motors in 1956 it came as a huge success in the market. It's main purpose was to run a single IBM central computer. Due to it's success, IBM took it forward and became the first company to develop operating systems and began distributing them.</p>
<p>In the 1960s the Bell labs introduced the first version of the Unix OS, it was the first system that could support multi-tasking and multi-user functionality. This system was written in C programming language and was freely available. It was widely accepted and adapted by many users this led to it's official release of the first version in the 70s. </p>
<p>With it's success on early stages it was widely accepted, which led to many operating systems used today borrow their origin from them. Some of the companies with their origin from UNIX include: Mac OS X, iOS, Android, Chrome OS etc...</p>
<p>1977 Apple Dos was introduced in the market. It was designed for home computers and it was a huge success. The designer of this OS was Steve Wozniak. Originally it was designed as a ROM, but in 1978 a first DOS was commissioned and it became a popular software.</p>
<p>Microsoft came into play in the year 1981, where they introduced MS-DOS. After it's launch it was shipped and used for the IBM personal computers. Later on in 1990 Windows 3.0 was launched, this became a rival to Apple's Macintosh GUI. </p>
<p>1992 Windows 3.1x was launched. This operating system introduced several enhancements like improvement in multimedia support and system usability just to list a few. Over the years Microsoft continued to improve their system with betterment from the user's side. The improvement has been seen long way till the recent system we have which is Windows 11.</p>
<p>In March 2008 Apple introduced iPhone OS 1, which was the first iOS for Apple's mobile OS. When the iPhone software development kit (iPhone SDK) was released, the operating system previously known as iPhone OS was later renamed to iOS.</p>
<p>Android OS was released on September 2008. It was developed by Google based on Linux Kernel. By this time Android became the first competitor iOS. </p>
<p>Today Apple, OS X, Windows and various forms of Linux dominate the market of the modern Operating System.</p>
<h2 id="heading-how-an-operating-system-works">How an Operating System Works</h2>
<p>The work-flow of a computer begins when you press the power button on your PC or even your phone. Once the power button is pressed the OS is the first program that runs. </p>
<p>In a real real-life scenario we can compare an OS to the government in a particular country. Just like the way governments offer different directives on services and regulations to run different departments the same way OS controls program executions in a machine.</p>
<p>Another scenario to describe this: If you were to travel to a place that you had never been to before, where they speak a language that you are not familiar with, how will you communicate with the locals? Obviously yo will need a translators help. That's exactly what an OS does in your computer. It converts the computer language into a human understandable language.</p>
<p>Without the help of an OS it will be difficult to run even a single program in a machine actually it will be very complex to execute a single task. With this simple understanding you are able to understand that one of the OS's role is to organize and control hardware and software so that the device it lives in does not only behave in a flexible but also predictable way.</p>
<h2 id="heading-types-of-operating-systems">Types of Operating Systems</h2>
<p>Operating Systems is one of the softwares that have been constantly updated over the past years. Different companies continuously working to provide best of their product to keep up with competitors.</p>
<p><strong>They Include:</strong></p>
<ol>
<li><strong>Real-time Operating System</strong></li>
</ol>
<p>The main aim of this system is executing real-time applications. It gives the maximum time for each of the critical operations that it performs. As a result, it guarantees the events will be processed in a given time.</p>
<p>This OS uses a specialized scheduling algorithms, this is to ensure that it switches tasks according to their priorities so that the deadlines are met for every task.</p>
<p>Some of the commonly known real-time OS include Windows CE, OS-9, and Symbian. Some common application of real-time include air traffic control systems, weapons control systems, industrial control systems, and control machinery.</p>
<ol start="2">
<li><strong>Multi-programming Operating System</strong></li>
</ol>
<p>They are also known as <em>Multi-tasking OS</em>. They are divided into two parts: 
pre-emptive and co-operative. </p>
<p>In pre-emptive the OS divides the CPU time and dedicates a slot to each of the assigned programs. It is similar to the multi-threading. On the other hand Cooperative is achieved by depending on each process to give time to the other processes in a defined manner. It is similar to block multi-threading.</p>
<p>The main goal in multiprogramming operating systems is to improve resource utilization and system throughput and this is achieved through organizing the computing jobs in a manner that ensures that the CPU always has a job to execute at any one time.</p>
<ol start="3">
<li><strong>Batch Operating System</strong></li>
</ol>
<p>The execution of programs is done in batches. Programs are collected, grouped and scheduled for later processing. This ensures faster processing speed for the programs.</p>
<p>Some problems associated with these operating systems include the lack of interaction between the user and the computer, difficulty in prioritizing tasks based on their urgency, and high CPU idle time caused by the low speed of the mechanical input and output devices. A good example of this system is the IBM's z/OS.</p>
<ol start="4">
<li><strong>Distributed Operating System</strong></li>
</ol>
<p>This is OS manages a group of independent machines and makes them appear as a single computer. They use powerful micro-processors that take advantage of the advancement in networking. </p>
<p>Distributed operating systems also ensure that there is a lighter load on the host machine even when performing heavy computations. A group of computers together in a cooperation form a distributed system.</p>
<h2 id="heading-examples-of-operating-systems">Examples of Operating Systems</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/01/fresh.png" alt="OS examples" width="600" height="400" loading="lazy"></p>
<p>Different types of OS means that we will have specific examples for each. Tech companies compete on daily basis to meet their customer's needs be it users of mobile phones, Desktops, laptops or the smart gadgets we have.</p>
<p>Below is a list of the most popular computer and smart-phone operating systems in the market today.</p>
<h3 id="heading-computer-os">Computer OS</h3>
<p><strong>Microsoft Windows</strong>
Developed by Microsoft, It is the most used OS among computer users. It's latest release is Windows 11, with some of it's older versions include: Windows 10, 8.1, 8, 7, Vista. XP and Windows 2000.</p>
<p>To install it you will need to purchase a copy of the software which is accompanied by a uniques product activation key.</p>
<p><strong>Mac OS</strong>
Developed by Apple for Apple computers. This OS comes pre-installed in all Macintosh computers.</p>
<p><strong>Linux</strong>
It is an Open-Source software, which has resulted to many distributions over the past years. It is considered to be used by people who know their way around working with the command line.</p>
<p>Some of it's distributions include: Ubuntu, Parrot, Debian, Arch, Linux Mint, Fedora, Kali Linux, and more.</p>
<p><em>Other rising OS among computer field include: <strong>Chrome OS &amp; Android</strong></em></p>
<h3 id="heading-smart-phone-os">Smart-phone OS</h3>
<p>Some of the most popular include: Android, Apple iOS, Windows Mobile, Blackberry OS, Palm OS, Google pixel and Symbian OS.</p>
<h2 id="heading-functions-of-an-operating-system">Functions of an Operating System</h2>
<p>Speaking of OS functions, has it ever crossed your mind how the computer manages to handle different processes, how different tasks are managed or even implemented?</p>
<p>If this questions have ever crossed your mind, then in this section they will be answered, all this are functions that are being handled by the OS, Let's talk more about the same below:</p>
<ol>
<li><p><strong>Memory Management</strong>
It's the work of the OS to manage the computer memory. With the help of the CPU the OS keeps track of the memory used by a particular program, It will be fair to mention that the OS ensures that each program is allocated enough memory to execute it's process</p>
</li>
<li><p><strong>Process Management</strong>
The OS is responsible for deciding the order in which processes will be executed, this act is known as process scheduling. Process management is made possible with the help of algorithms. Other responsibilities that lie under this category include: keeping status of a process and ensuring each process receives enough time to execute.</p>
</li>
<li><p><strong>Device Management</strong>
It monitors all devices connected to your device, both the input and output devices. It's main function is to ensure that all the connected devices are correctly allocated and function. It also decides which process gets access to a certain device and for how long.</p>
</li>
<li><p><strong>File Management</strong>
As we all know a system do contain multiple and large amount of data. It's the work of the OS to keep track of all this information including their location, accessibility rights, where they are stored, status of the file. It also manages the process of file deletion.</p>
</li>
<li><p><strong>Job Scheduling</strong>
The operating system determines the jobs/tasks that need to be processed first and ensures that these tasks are completed. Usually the one with the highest priority is executed first. It also keeps track of the time and resources used by various tasks and users.</p>
</li>
<li><p><strong>Error Detection &amp; Response</strong>
When a computer is running we are bount to encounter a number of errors, by the computer being able to indicate or show you where this is made possible with the help of the OS. The OS offers helps by a response that guides you on what to do next.</p>
</li>
</ol>
<h2 id="heading-advantages-and-disadvantages-of-operating-systems">Advantages and Disadvantages of Operating Systems</h2>
<p>By this point it is evident that OS plays a big role in our day to day life. It is within our midist either your phone or even you laptop or the PC back at the office.</p>
<p>With the different types we have they all have their benefits and downsides, that's why there will always be new versions released time after time. Let's have a look at some of the pros and cons of an OS.</p>
<h3 id="heading-advantages">Advantages</h3>
<ol>
<li><p><strong>Resource Sharing</strong>
Operating System allows for an opportunity to share resources with other users via services like printers, fax, over the network etc... some of the most commonly shared resources include: files documents, videos, images and apps, mails.</p>
</li>
<li><p><strong>Security</strong>
With the large amount of data stored in the computers it's the responsibility of an OS to make sure all the data present is secure. A good example of an OS actively securing user data is the Microsoft's Windows Defender, it detects malicious and harmful files and removes them or denies access to install.</p>
</li>
<li><p><strong>User Friendly</strong>
The interface provided by the GUI is much more user friendly compared to a command line interface. It comes with various symbols, buttons, menus and other graphical representations which all make them easily understandable. As a result, users can interact and communicate with the machine easily.</p>
</li>
<li><p><strong>Multitasking</strong> 
By using an operating system, users can perform different tasks simultaneously. There is no need to close one window to open another.</p>
</li>
</ol>
<h3 id="heading-disadvantages">Disadvantages</h3>
<ol>
<li><p><strong>Cost</strong>
Unless it is an open-source operating system like Linux and it's distros, most Operating Systems are considered to be expensive. Even though users can choose free versions of them, they typically have limited features.</p>
</li>
<li><p><strong>Virus Attacks</strong>
Just like any other software out there, the risk of viruses is always higher in an operating system. Sometimes users can unknowingly download malicious programs, visit malicious websites, or open email attachments containing viruses, all which can make a computer vulnerable to viruses.</p>
</li>
<li><p><strong>Complexity</strong>
The languages used to develop the OS are more complex for people without programming knowledge. So you can't always quickly resolve problems in the OS just by looking you will have to look for a specialist to help hence maintenance cost rises.</p>
</li>
<li><p><strong>System Failure</strong>
An operating system is the heart of the computer system, and if by any chance, due to any reason, it stops functioning, then the whole system will crash. Meaning without an OS your machine can not function at all.</p>
</li>
</ol>
<h2 id="heading-how-to-choose-an-operating-system">How to Choose an Operating System</h2>
<p>By knowing what to look for when choosing an OS, will have a big impact on your daily interaction with computer. It is always advised to shop keeping in mind the budget at hand and the features you are aspiring for this also depends with your career.</p>
<p>Here are the common actors to consider:</p>
<ol>
<li><p><strong>User-friendliness</strong>
Each OS has a new thing it has to offer, especially for the beginners. Be sure the OS you choose has an easier learning curve and you can easily adapt to it. Linux and it's distributions have always been considered less user friendly to beginners with OS like windows being more friendly.</p>
</li>
<li><p><strong>Software Compatibility</strong>
Be sure to chore an OS that supports installation of the softwares you use on daily basis or even plan to use. A good example is windows system supports a wide variety of commercial softwares unlike Mac which mostly supports softwares from it's library only.</p>
</li>
<li><p><strong>Hardware Configuration</strong>
You'll want to make sure that you'll have access to the software that you use in service delivery. You just need the software that will help you deliver your services. Pick the operating system that has everything that you need with full support and updates.</p>
</li>
<li><p><strong>Cost &amp; Support</strong>
You will need to make sure that the price range is within your budget. Mac generally costs more than most of the others. It is possible to get a cheaper or free OS that effectively serves every purpose you'll need it to serve.</p>
</li>
<li><p><strong>Security</strong>
As discussed from the disadvantages since an OS is just like any other software it's vulnerable to attacks. Be sure to choose an OS that has high security measures. Usually Windows is considered to be more vulnerable due to it's wide market share while Linux distros are considered less vulnerable</p>
</li>
</ol>
<h2 id="heading-wrap-up">Wrap Up</h2>
<p>Perhaps you are still wondering what people's take is on the longest debate about the OS best for developers, well according to many surveys and polls conducted by different organizations windows has always managed to scope the top position: </p>
<p>According to the latest Stack Overflow survey, over 80,000 developers were asked that same question. and here is the overall say:
<img src="https://www.freecodecamp.org/news/content/images/2022/01/operating.png" alt="operating" width="600" height="400" loading="lazy"></p>
<p>There you have it, all the knowledge you require to help you get around the OS topic, having said this hope this article has helped you out and if you are a beginner all the best as you find the best OS for your work.</p>
<p>Enjoy coding ❤.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Copy a Directory in Linux – How to cp a Folder in the Command Line in Linux and Unix (MacOS) ]]>
                </title>
                <description>
                    <![CDATA[ By John Mosesman To copy files or directories in Unix-based operating systems (Linux and MacOS), you use the cp command. The cp command is a relatively simple command, but its behavior changes slightly depending on the inputs (files vs directories) a... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/copy-a-directory-in-linux-how-to-cp-a-folder-in-the-command-line-in-linux-and-unix-macos/</link>
                <guid isPermaLink="false">66d45f62b6b7f664236cbde9</guid>
                
                    <category>
                        <![CDATA[ Linux ]]>
                    </category>
                
                    <category>
                        <![CDATA[ macOS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ unix ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 04 May 2021 15:33:12 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/05/copy-directory-linux-article.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By John Mosesman</p>
<p>To copy files or directories in Unix-based operating systems (Linux and MacOS), you use the <code>cp</code> command.</p>
<p>The <code>cp</code> command is a relatively simple command, but its behavior changes slightly depending on the inputs (files vs directories) and the options you pass to it.</p>
<p>To view the documentation or manual for the <code>cp</code> command, run <code>man cp</code> at your terminal:</p>
<pre><code>$ man cp

NAME
     cp -- copy files

SYNOPSIS
     cp [OPTIONS] source_file target_file
     cp [OPTIONS] source_file ... target_directory

...
</code></pre><p>The basic form of this command takes an input source (or sources) that you want to copy (files or directories) and a destination to copy the files or directories to:</p>
<pre><code>cp [OPTIONS] source_file target_file
</code></pre><h2 id="heading-how-to-copy-a-file-to-the-current-directory">How to copy a file to the current directory</h2>
<p>To copy a file, pass the file you want to copy and the path of where you want to copy the file to.</p>
<p>If you have a file named <code>a.txt</code>, and you want a copy of that file named <code>b.txt</code>:</p>
<pre><code>$ ls
a.txt

$ cp a.txt b.txt

$ ls
a.txt   b.txt
</code></pre><blockquote>
<p>If you're not familiar with the <code>ls</code> command, <code>ls</code> "lists" all the contents of a directory.</p>
</blockquote>
<p>By default the <code>cp</code> command uses <em>your</em> <em>current directory</em> as the path.</p>
<h3 id="heading-how-to-copy-a-file-to-another-directory">How to copy a file to another directory</h3>
<p>To copy a file to a directory that is <em>different</em> from your current directory, you just need to pass the path of the other directory as the destination:</p>
<pre><code>$ ls ../directory<span class="hljs-number">-1</span>/

$ cp a.txt ../directory<span class="hljs-number">-1</span>/

$ ls ../directory<span class="hljs-number">-1</span>/
a.txt
</code></pre><p>After the <code>cp</code>  command, the previously empty <code>directory-1</code> now contains the file <code>a.txt</code>.</p>
<p>By default the copied file receives the name of the original file, but you can also optionally pass a file name as well:</p>
<pre><code>$ cp a.txt ../directory<span class="hljs-number">-1</span>/b.txt

$ ls ../directory<span class="hljs-number">-1</span>/
b.txt
</code></pre><h2 id="heading-how-to-copy-multiple-files-to-a-directory">How to copy multiple files to a directory</h2>
<p>To copy more than one file at a time you can pass multiple input sources and a directory as destination:</p>
<pre><code>$ ls ../directory<span class="hljs-number">-1</span>/

$ cp first.txt second.txt ../directory<span class="hljs-number">-1</span>/

$ ls ../directory<span class="hljs-number">-1</span>/
first.txt       second.txt
</code></pre><p>Here the two input sources (<code>first.txt</code> and <code>second.txt</code>) were both copied to the directory <code>directory-1</code>.</p>
<blockquote>
<p><strong>Note:</strong> when passing multiple sources the last argument must be a directory.</p>
</blockquote>
<h2 id="heading-how-to-copy-a-directory-to-another-directory">How to copy a directory to another directory</h2>
<p>If you try to pass a directory as the input source, you get this error:</p>
<pre><code>$ cp directory<span class="hljs-number">-1</span> directory<span class="hljs-number">-2</span>
<span class="hljs-attr">cp</span>: directory<span class="hljs-number">-1</span> is a directory (not copied).
</code></pre><p>To copy a directory, you need to add the <code>-r</code> (or <code>-R</code>) flag—which is shorthand for <code>--recursive</code>:</p>
<pre><code>$ ls directory<span class="hljs-number">-1</span>
a.txt

$ cp -r directory<span class="hljs-number">-1</span> directory<span class="hljs-number">-2</span>

$ ls
directory<span class="hljs-number">-1</span>          directory<span class="hljs-number">-2</span>

$ ls directory<span class="hljs-number">-2</span>
a.txt
</code></pre><p>Here <code>directory-1</code> containing the file <code>a.txt</code> is copied to a new directory called <code>directory-2</code>—which now also contains the file <code>a.txt</code>.</p>
<h3 id="heading-how-to-copy-the-entire-directory-vs-the-contents-of-the-directory">How to copy the entire directory vs the contents of the directory</h3>
<p>There is an interesting edge case when you copy a directory: if the destination directory already exists, you can choose whether to copy <strong>the contents of the directory</strong> or the <strong>entire directory</strong> by adding or removing a trailing <code>/</code> from your input.</p>
<p>Here's the description from the <code>-R</code> option of the <code>man</code> page:</p>
<blockquote>
<p>If source_file designates a directory, cp copies the directory and the entire subtree connected at that point. If the source_file ends in a /, the contents of the directory are copied rather than the directory itself.</p>
</blockquote>
<p>If you want to copy <em>just the contents</em> of the directory into another directory, add a trailing <code>/</code> to your input.</p>
<p>If you want to copy the contents of the directory <em>and the directory folder itself</em> into another directory, don't add a trailing <code>/</code>:</p>
<pre><code>$ ls
directory<span class="hljs-number">-1</span>          directory<span class="hljs-number">-2</span>

$ ls directory<span class="hljs-number">-2</span>

$ cp -r directory<span class="hljs-number">-1</span> directory<span class="hljs-number">-2</span>

$ ls directory<span class="hljs-number">-2</span>
directory<span class="hljs-number">-1</span>

$ ls directory<span class="hljs-number">-2</span>/directory<span class="hljs-number">-1</span>
a.txt
</code></pre><p>Here you can see that because <code>directory-2</code> already exists—and the input source didn't have a trailing <code>/</code>—both the contents of <code>directory-1</code> <em>and</em> the directory itself was copied into the destination.</p>
<h2 id="heading-how-to-prevent-overwriting-files-with-cp">How to prevent overwriting files with <code>cp</code></h2>
<p>By default, the <code>cp</code> command will overwrite existing files:</p>
<pre><code>$ cat a.txt
A

$ cat directory<span class="hljs-number">-1</span>/a.txt
B

$ cp a.txt directory<span class="hljs-number">-1</span>/a.txt

$ cat directory<span class="hljs-number">-1</span>/a.txt
A
</code></pre><blockquote>
<p>If you're not familiar with the <code>cat</code> or "concatenate" command, it prints the contents of a file.</p>
</blockquote>
<p>There are two ways to prevent this.</p>
<h3 id="heading-the-interactive-flag">The interactive flag</h3>
<p>To be prompted when an overwrite is about to occur, you can add the <code>-i</code> or <code>--interactive</code> flag:</p>
<pre><code>$ cp -i a.txt directory<span class="hljs-number">-1</span>/a.txt
overwrite directory<span class="hljs-number">-1</span>/a.txt? (y/n [n])
</code></pre><h3 id="heading-the-no-clobber-flag">The no-clobber flag</h3>
<p>Or, to prevent overwrites without being prompted, you can add the <code>-n</code> or <code>--no-clobber</code> flag:</p>
<pre><code>$ cat a.txt
A

$ cat directory<span class="hljs-number">-1</span>/a.txt
B

$ cp -n a.txt directory<span class="hljs-number">-1</span>/a.txt

$ cat directory<span class="hljs-number">-1</span>/a.txt
B
</code></pre><p>Here you can see that thanks to the <code>-n</code> flag the contents of <code>directory-1/a.txt</code> were not overwritten.</p>
<h2 id="heading-other-options">Other options</h2>
<p>There are many other useful options to pass to the <code>cp</code> command: like <code>-v</code> for "verbose" output or <code>-f</code> for "force." </p>
<p>I highly encourage you to read through the <code>man</code> page for all of the other useful options.</p>
<p>If you liked this tutorial, I also talk about topics like this <a target="_blank" href="https://twitter.com/johnmosesman">on Twitter</a>, and write about them on <a target="_blank" href="https://johnmosesman.com/">my site</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Bashrc Customization Guide – How to Add Aliases, Use Functions, and More ]]>
                </title>
                <description>
                    <![CDATA[ By Brandon Wallace Customizing your .bashrc file can greatly improve your workflow and increase your productivity.  The .bashrc is a standard file located in your Linux home directory. In this article I will show you useful .bashrc options, aliases, ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/bashrc-customization-guide/</link>
                <guid isPermaLink="false">66d84e4e29e30bc0ad477555</guid>
                
                    <category>
                        <![CDATA[ Bash ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Linux ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Productivity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ shell script ]]>
                    </category>
                
                    <category>
                        <![CDATA[ unix ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 17 Mar 2021 22:40:57 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/03/bashrc_cover_image2-1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Brandon Wallace</p>
<p>Customizing your .bashrc file can greatly improve your workflow and increase your productivity. </p>
<p>The .bashrc is a standard file located in your Linux home directory. In this article I will show you useful .bashrc options, aliases, functions, and more.</p>
<p>The main benefits of configuring the .bashrc file are:</p>
<ul>
<li>Adding aliases allows you to type commands faster, saving you time.</li>
<li>Adding functions allows you to save and rerun complex code.</li>
<li>It displays useful system information.</li>
<li>It customizes the Bash prompt.</li>
</ul>
<h2 id="heading-how-to-get-started-with-editing-bashrc">How to Get Started with Editing .bashrc</h2>
<p>Here's how you can edit the .bashrc file with a text editor:</p>
<pre><code class="lang-bash">$ vim ~/.bashrc
</code></pre>
<p>You can add date and time formatting to bash history.</p>
<pre><code class="lang-bash">HISTTIMEFORMAT=<span class="hljs-string">"%F %T "</span>
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment"># Output</span>

$ <span class="hljs-built_in">history</span>
 1017  20210228 10:51:28  uptime
 1019  20210228 10:52:42  free -m
 1020  20210228 10:52:49  tree --dirsfirst -F
 1018  20210228 10:51:38  xrandr | awk <span class="hljs-string">'/\*/{print $1}'</span>
</code></pre>
<p>Add this line to ignore duplicate commands in the history.</p>
<pre><code class="lang-bash">HISTCONTROL=ignoredups
</code></pre>
<p>To set the number of lines in active history and to set the number of lines saved in Bash history, add these two lines.</p>
<pre><code class="lang-bash">HISTSIZE=2000
HISTFILESIZE=2000
</code></pre>
<p>You can set your history to append instead of overwriting Bash history. <strong><code>shopt</code></strong> stands for "shell options". </p>
<pre><code class="lang-bash"><span class="hljs-built_in">shopt</span> -s histappend
</code></pre>
<p>To see all the default shell options, run <code>shopt -p</code>.</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Output</span>

$ <span class="hljs-built_in">shopt</span> -p

<span class="hljs-built_in">shopt</span> -u autocd                   
<span class="hljs-built_in">shopt</span> -u assoc_expand_once        
<span class="hljs-built_in">shopt</span> -u cdable_vars              
<span class="hljs-built_in">shopt</span> -u cdspell                  
<span class="hljs-built_in">shopt</span> -u checkhash                
<span class="hljs-built_in">shopt</span> -u checkjobs                
<span class="hljs-built_in">shopt</span> -s checkwinsize             
[...]
</code></pre>
<p>Create some variables to add color to the Bash prompt like this:</p>
<pre><code class="lang-bash">blk=<span class="hljs-string">'\[\033[01;30m\]'</span>   <span class="hljs-comment"># Black</span>
red=<span class="hljs-string">'\[\033[01;31m\]'</span>   <span class="hljs-comment"># Red</span>
grn=<span class="hljs-string">'\[\033[01;32m\]'</span>   <span class="hljs-comment"># Green</span>
ylw=<span class="hljs-string">'\[\033[01;33m\]'</span>   <span class="hljs-comment"># Yellow</span>
blu=<span class="hljs-string">'\[\033[01;34m\]'</span>   <span class="hljs-comment"># Blue</span>
pur=<span class="hljs-string">'\[\033[01;35m\]'</span>   <span class="hljs-comment"># Purple</span>
cyn=<span class="hljs-string">'\[\033[01;36m\]'</span>   <span class="hljs-comment"># Cyan</span>
wht=<span class="hljs-string">'\[\033[01;37m\]'</span>   <span class="hljs-comment"># White</span>
clr=<span class="hljs-string">'\[\033[00m\]'</span>      <span class="hljs-comment"># Reset</span>
</code></pre>
<p>This is for the Vim lovers. This will allow you to use vim commands on the command line. This is always the first line I add to my .bashrc.</p>
<pre><code class="lang-bash"><span class="hljs-built_in">set</span> -o vi
</code></pre>
<h2 id="heading-how-to-create-aliases-in-bashrc">How to Create Aliases in .bashrc</h2>
<p>You can use aliases for commands you run a lot. Creating aliases will allow you to type faster, saving time and increasing productivity. </p>
<p>The syntax for creating an alias is <code>alias &lt;my_alias&gt;='longer command'</code>. To find out which commands would make good aliases, run this command to see a list of the top 10 commands you run most.</p>
<pre><code class="lang-bash">$ <span class="hljs-built_in">history</span> | awk <span class="hljs-string">'{cmd[$2]++} END {for(elem in cmd) {print cmd[elem] " " elem}}'</span> | sort -n -r | head -10
</code></pre>
<pre><code># Output

<span class="hljs-number">171</span> git
<span class="hljs-number">108</span> cd
<span class="hljs-number">62</span> vim
<span class="hljs-number">51</span> python3
<span class="hljs-number">38</span> history
<span class="hljs-number">32</span> exit
<span class="hljs-number">30</span> clear
<span class="hljs-number">28</span> tmux
<span class="hljs-number">28</span> tree
<span class="hljs-number">27</span> ls
</code></pre><p>Since I use Git a lot, that would be a great command to create an alias for.</p>
<pre><code class="lang-bash"><span class="hljs-comment"># View Git status.</span>
<span class="hljs-built_in">alias</span> gs=<span class="hljs-string">'git status'</span>

<span class="hljs-comment"># Add a file to Git.</span>
<span class="hljs-built_in">alias</span> ga=<span class="hljs-string">'git add'</span>

<span class="hljs-comment"># Add all files to Git.</span>
<span class="hljs-built_in">alias</span> gaa=<span class="hljs-string">'git add --all'</span>

<span class="hljs-comment"># Commit changes to the code.</span>
<span class="hljs-built_in">alias</span> gc=<span class="hljs-string">'git commit'</span>

<span class="hljs-comment"># View the Git log.</span>
<span class="hljs-built_in">alias</span> gl=<span class="hljs-string">'git log --oneline'</span>

<span class="hljs-comment"># Create a new Git branch and move to the new branch at the same time. </span>
<span class="hljs-built_in">alias</span> gb=<span class="hljs-string">'git checkout -b'</span>

<span class="hljs-comment"># View the difference.</span>
<span class="hljs-built_in">alias</span> gd=<span class="hljs-string">'git diff'</span>
</code></pre>
<p>Here are some other useful aliases:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Move to the parent folder.</span>
<span class="hljs-built_in">alias</span> ..=<span class="hljs-string">'cd ..;pwd'</span>

<span class="hljs-comment"># Move up two parent folders.</span>
<span class="hljs-built_in">alias</span> ...=<span class="hljs-string">'cd ../..;pwd'</span>

<span class="hljs-comment"># Move up three parent folders.</span>
<span class="hljs-built_in">alias</span> ....=<span class="hljs-string">'cd ../../..;pwd'</span>
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment"># Press c to clear the terminal screen.</span>
<span class="hljs-built_in">alias</span> c=<span class="hljs-string">'clear'</span>

<span class="hljs-comment"># Press h to view the bash history.</span>
<span class="hljs-built_in">alias</span> h=<span class="hljs-string">'history'</span>

<span class="hljs-comment"># Display the directory structure better.</span>
<span class="hljs-built_in">alias</span> tree=<span class="hljs-string">'tree --dirsfirst -F'</span>

<span class="hljs-comment"># Make a directory and all parent directories with verbosity.</span>
<span class="hljs-built_in">alias</span> mkdir=<span class="hljs-string">'mkdir -p -v'</span>
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment"># View the calender by typing the first three letters of the month.</span>

<span class="hljs-built_in">alias</span> jan=<span class="hljs-string">'cal -m 01'</span>
<span class="hljs-built_in">alias</span> feb=<span class="hljs-string">'cal -m 02'</span>
<span class="hljs-built_in">alias</span> mar=<span class="hljs-string">'cal -m 03'</span>
<span class="hljs-built_in">alias</span> apr=<span class="hljs-string">'cal -m 04'</span>
<span class="hljs-built_in">alias</span> may=<span class="hljs-string">'cal -m 05'</span>
<span class="hljs-built_in">alias</span> jun=<span class="hljs-string">'cal -m 06'</span>
<span class="hljs-built_in">alias</span> jul=<span class="hljs-string">'cal -m 07'</span>
<span class="hljs-built_in">alias</span> aug=<span class="hljs-string">'cal -m 08'</span>
<span class="hljs-built_in">alias</span> sep=<span class="hljs-string">'cal -m 09'</span>
<span class="hljs-built_in">alias</span> oct=<span class="hljs-string">'cal -m 10'</span>
<span class="hljs-built_in">alias</span> nov=<span class="hljs-string">'cal -m 11'</span>
<span class="hljs-built_in">alias</span> dec=<span class="hljs-string">'cal -m 12'</span>
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment"># Output</span>

$ mar

     March 2021      
Su Mo Tu We Th Fr Sa 
    1  2  3  4  5  6 
 7  8  9 10 11 12 13 
14 15 16 17 18 19 20 
21 22 23 24 25 26 27 
28 29 30 31
</code></pre>
<h2 id="heading-how-to-use-functions-in-bashrc">How to Use Functions in .bashrc</h2>
<p>Functions are great for more complicated code when an alias won't work.</p>
<p>Here's the basic function syntax:</p>
<pre><code class="lang-bash"><span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">funct_name</span></span>() {
    <span class="hljs-comment"># code;</span>
}
</code></pre>
<p>This is how you can find the largest files in a directory:</p>
<pre><code class="lang-bash"><span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">find_largest_files</span></span>() {
    du -h -x -s -- * | sort -r -h | head -20;
}
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment"># Output</span>

Downloads $ find_largest_files

709M    systemrescue-8.00-amd64.iso
337M    debian-10.8.0-amd64-netinst.iso
9.1M    weather-icons-master.zip
6.3M    Hack-font.zip
3.9M    city.list.json.gz
2.8M    dvdrental.tar
708K    IMG_2600.JPG
100K    sql_cheat_sheet_pgsql.pdf
4.0K    repeating-a-string.txt
4.0K    heart.svg
4.0K    Fedora-Workstation-33-1.2-x86_64-CHECKSUM
[...]
</code></pre>
<p>You can also add colors to the Bash prompt and display the current Git branch like this:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Display the current Git branch in the Bash prompt.</span>

<span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">git_branch</span></span>() {
    <span class="hljs-keyword">if</span> [ -d .git ] ; <span class="hljs-keyword">then</span>
        <span class="hljs-built_in">printf</span> <span class="hljs-string">"%s"</span> <span class="hljs-string">"(<span class="hljs-subst">$(git branch 2&gt; /dev/null | awk '/\*/{print $2}')</span>)"</span>;
    <span class="hljs-keyword">fi</span>
}

<span class="hljs-comment"># Set the prompt.</span>

<span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">bash_prompt</span></span>(){
    PS1=<span class="hljs-string">'${debian_chroot:+($debian_chroot)}'</span><span class="hljs-variable">${blu}</span><span class="hljs-string">'$(git_branch)'</span><span class="hljs-variable">${pur}</span><span class="hljs-string">' \W'</span><span class="hljs-variable">${grn}</span><span class="hljs-string">' \$ '</span><span class="hljs-variable">${clr}</span>
}

bash_prompt
</code></pre>
<p><img src="https://i.postimg.cc/mgg56Zjp/bash-prompt.png" alt="bash-prompt.png" width="740" height="126" loading="lazy">
<em>Custom Bash prompt</em></p>
<p>Grep (search) through your history for previous run commands:</p>
<pre><code class="lang-bash"><span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">hg</span></span>() {
    <span class="hljs-built_in">history</span> | grep <span class="hljs-string">"<span class="hljs-variable">$1</span>"</span>;
}
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment"># Output</span>

$ hg vim

305  2021-03-02 16:47:33 vim .bashrc
307  2021-03-02 17:17:09 vim .tmux.conf
</code></pre>
<p>This is how you start a new project with Git:</p>
<pre><code class="lang-bash"><span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">git_init</span></span>() {
    <span class="hljs-keyword">if</span> [ -z <span class="hljs-string">"<span class="hljs-variable">$1</span>"</span> ]; <span class="hljs-keyword">then</span>
        <span class="hljs-built_in">printf</span> <span class="hljs-string">"%s\n"</span> <span class="hljs-string">"Please provide a directory name."</span>;
    <span class="hljs-keyword">else</span>
        mkdir <span class="hljs-string">"<span class="hljs-variable">$1</span>"</span>;
        <span class="hljs-built_in">builtin</span> <span class="hljs-built_in">cd</span> <span class="hljs-string">"<span class="hljs-variable">$1</span>"</span>;
        <span class="hljs-built_in">pwd</span>;
        git init;
        touch readme.md .gitignore LICENSE;
        <span class="hljs-built_in">echo</span> <span class="hljs-string">"# <span class="hljs-subst">$(basename $PWD)</span>"</span> &gt;&gt; readme.md
    <span class="hljs-keyword">fi</span>
}
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment"># Output</span>

$ git_init my_project

/home/brandon/my_project
Initialized empty Git repository <span class="hljs-keyword">in</span> /home/brandon/my_project/.git/
</code></pre>
<p>You can also get the weather report on the command line. This requires the package <strong>curl</strong>, <strong>jq</strong>, and an <a target="_blank" href="https://openweathermap.org/api"><strong>API key</strong></a> from <a target="_blank" href="https://openweathermap.org/">Openweathermap.</a> Read the <a target="_blank" href="https://openweathermap.org/api">Openweathermap API documentation</a> in order to configure the URL correctly to get the weather in your location.</p>
<p>Install curl and jq with these commands:</p>
<pre><code class="lang-bash">$ sudo apt install curl jq

<span class="hljs-comment"># OR</span>

$ sudo dnf install curl jq
</code></pre>
<pre><code class="lang-bash"><span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">weather_report</span></span>() {

    <span class="hljs-built_in">local</span> response=$(curl --silent <span class="hljs-string">'https://api.openweathermap.org/data/2.5/weather?id=5128581&amp;units=imperial&amp;appid=&lt;YOUR_API_KEY&gt;'</span>) 

    <span class="hljs-built_in">local</span> status=$(<span class="hljs-built_in">echo</span> <span class="hljs-variable">$response</span> | jq -r <span class="hljs-string">'.cod'</span>)

    <span class="hljs-comment"># Check for the 200 response indicating a successful API query.</span>
    <span class="hljs-keyword">case</span> <span class="hljs-variable">$status</span> <span class="hljs-keyword">in</span>

        200) <span class="hljs-built_in">printf</span> <span class="hljs-string">"Location: %s %s\n"</span> <span class="hljs-string">"<span class="hljs-subst">$(echo $response | jq '.name')</span> <span class="hljs-subst">$(echo $response | jq '.sys.country')</span>"</span>  
             <span class="hljs-built_in">printf</span> <span class="hljs-string">"Forecast: %s\n"</span> <span class="hljs-string">"<span class="hljs-subst">$(echo $response | jq '.weather[].description')</span>"</span> 
             <span class="hljs-built_in">printf</span> <span class="hljs-string">"Temperature: %.1f°F\n"</span> <span class="hljs-string">"<span class="hljs-subst">$(echo $response | jq '.main.temp')</span>"</span> 
             <span class="hljs-built_in">printf</span> <span class="hljs-string">"Temp Min: %.1f°F\n"</span> <span class="hljs-string">"<span class="hljs-subst">$(echo $response | jq '.main.temp_min')</span>"</span> 
             <span class="hljs-built_in">printf</span> <span class="hljs-string">"Temp Max: %.1f°F\n"</span> <span class="hljs-string">"<span class="hljs-subst">$(echo $response | jq '.main.temp_max')</span>"</span> 
            ;;
        401) <span class="hljs-built_in">echo</span> <span class="hljs-string">"401 error"</span>
            ;;
        *) <span class="hljs-built_in">echo</span> <span class="hljs-string">"error"</span>
            ;;

    <span class="hljs-keyword">esac</span>

}
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment"># Output</span>

$ weather_report

Location: <span class="hljs-string">"New York"</span> <span class="hljs-string">"US"</span>
Forecast: <span class="hljs-string">"clear sky"</span>
Temperature: 58.0°F
Temp Min: 56.0°F
Temp Max: 60.8°F
</code></pre>
<h2 id="heading-how-to-print-system-information-in-bashrc">How to Print System Information in .bashrc</h2>
<p>You can display useful system information when you open the terminal like this:</p>
<pre><code class="lang-bash">clear

<span class="hljs-built_in">printf</span> <span class="hljs-string">"\n"</span>
<span class="hljs-built_in">printf</span> <span class="hljs-string">"   %s\n"</span> <span class="hljs-string">"IP ADDR: <span class="hljs-subst">$(curl ifconfig.me)</span>"</span>
<span class="hljs-built_in">printf</span> <span class="hljs-string">"   %s\n"</span> <span class="hljs-string">"USER: <span class="hljs-subst">$(echo $USER)</span>"</span>
<span class="hljs-built_in">printf</span> <span class="hljs-string">"   %s\n"</span> <span class="hljs-string">"DATE: <span class="hljs-subst">$(date)</span>"</span>
<span class="hljs-built_in">printf</span> <span class="hljs-string">"   %s\n"</span> <span class="hljs-string">"UPTIME: <span class="hljs-subst">$(uptime -p)</span>"</span>
<span class="hljs-built_in">printf</span> <span class="hljs-string">"   %s\n"</span> <span class="hljs-string">"HOSTNAME: <span class="hljs-subst">$(hostname -f)</span>"</span>
<span class="hljs-built_in">printf</span> <span class="hljs-string">"   %s\n"</span> <span class="hljs-string">"CPU: <span class="hljs-subst">$(awk -F: '/model name/{print $2}' | head -1)</span>"</span>
<span class="hljs-built_in">printf</span> <span class="hljs-string">"   %s\n"</span> <span class="hljs-string">"KERNEL: <span class="hljs-subst">$(uname -rms)</span>"</span>
<span class="hljs-built_in">printf</span> <span class="hljs-string">"   %s\n"</span> <span class="hljs-string">"PACKAGES: <span class="hljs-subst">$(dpkg --get-selections | wc -l)</span>"</span>
<span class="hljs-built_in">printf</span> <span class="hljs-string">"   %s\n"</span> <span class="hljs-string">"RESOLUTION: <span class="hljs-subst">$(xrandr | awk '/\*/{printf $1<span class="hljs-string">" "</span>}')</span>"</span>
<span class="hljs-built_in">printf</span> <span class="hljs-string">"   %s\n"</span> <span class="hljs-string">"MEMORY: <span class="hljs-subst">$(free -m -h | awk '/Mem/{print $3<span class="hljs-string">"/"</span>$2}')</span>"</span>
<span class="hljs-built_in">printf</span> <span class="hljs-string">"\n"</span>
</code></pre>
<p>Output:</p>
<p><img src="https://i.postimg.cc/8k6pNN39/Screenshot-2021-03-15-23-39-29.png" alt="Screenshot-2021-03-15-23-39-29.png" width="740" height="426" loading="lazy"></p>
<p>Source the .bashrc file to make the changes take effect:</p>
<pre><code class="lang-bash">$ <span class="hljs-built_in">source</span> ~/.bashrc
</code></pre>
<p>Here are all these custom .bashrc settings together. On a new system I paste any customization below the default code in the .bashrc file.</p>
<pre><code class="lang-bash"><span class="hljs-comment">######################################################################</span>
<span class="hljs-comment">#</span>
<span class="hljs-comment">#</span>
<span class="hljs-comment">#           ██████╗  █████╗ ███████╗██╗  ██╗██████╗  ██████╗</span>
<span class="hljs-comment">#           ██╔══██╗██╔══██╗██╔════╝██║  ██║██╔══██╗██╔════╝</span>
<span class="hljs-comment">#           ██████╔╝███████║███████╗███████║██████╔╝██║     </span>
<span class="hljs-comment">#           ██╔══██╗██╔══██║╚════██║██╔══██║██╔══██╗██║     </span>
<span class="hljs-comment">#           ██████╔╝██║  ██║███████║██║  ██║██║  ██║╚██████╗</span>
<span class="hljs-comment">#           ╚═════╝ ╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝ ╚═════╝</span>
<span class="hljs-comment">#</span>
<span class="hljs-comment">#</span>
<span class="hljs-comment">######################################################################</span>

<span class="hljs-built_in">set</span> -o vi

HISTTIMEFORMAT=<span class="hljs-string">"%F %T "</span>

HISTCONTROL=ignoredups

HISTSIZE=2000

HISTFILESIZE=2000

<span class="hljs-built_in">shopt</span> -s histappend

blk=<span class="hljs-string">'\[\033[01;30m\]'</span>   <span class="hljs-comment"># Black</span>
red=<span class="hljs-string">'\[\033[01;31m\]'</span>   <span class="hljs-comment"># Red</span>
grn=<span class="hljs-string">'\[\033[01;32m\]'</span>   <span class="hljs-comment"># Green</span>
ylw=<span class="hljs-string">'\[\033[01;33m\]'</span>   <span class="hljs-comment"># Yellow</span>
blu=<span class="hljs-string">'\[\033[01;34m\]'</span>   <span class="hljs-comment"># Blue</span>
pur=<span class="hljs-string">'\[\033[01;35m\]'</span>   <span class="hljs-comment"># Purple</span>
cyn=<span class="hljs-string">'\[\033[01;36m\]'</span>   <span class="hljs-comment"># Cyan</span>
wht=<span class="hljs-string">'\[\033[01;37m\]'</span>   <span class="hljs-comment"># White</span>
clr=<span class="hljs-string">'\[\033[00m\]'</span>      <span class="hljs-comment"># Reset</span>

<span class="hljs-built_in">alias</span> gs=<span class="hljs-string">'git status'</span>

<span class="hljs-built_in">alias</span> ga=<span class="hljs-string">'git add'</span>

<span class="hljs-built_in">alias</span> gaa=<span class="hljs-string">'git add --all'</span>

<span class="hljs-built_in">alias</span> gc=<span class="hljs-string">'git commit'</span>

<span class="hljs-built_in">alias</span> gl=<span class="hljs-string">'git log --oneline'</span>

<span class="hljs-built_in">alias</span> gb=<span class="hljs-string">'git checkout -b'</span>

<span class="hljs-built_in">alias</span> gd=<span class="hljs-string">'git diff'</span>

<span class="hljs-built_in">alias</span> ..=<span class="hljs-string">'cd ..;pwd'</span>

<span class="hljs-built_in">alias</span> ...=<span class="hljs-string">'cd ../..;pwd'</span>

<span class="hljs-built_in">alias</span> ....=<span class="hljs-string">'cd ../../..;pwd'</span>

<span class="hljs-built_in">alias</span> c=<span class="hljs-string">'clear'</span>

<span class="hljs-built_in">alias</span> h=<span class="hljs-string">'history'</span>

<span class="hljs-built_in">alias</span> tree=<span class="hljs-string">'tree --dirsfirst -F'</span>

<span class="hljs-built_in">alias</span> mkdir=<span class="hljs-string">'mkdir -p -v'</span>

<span class="hljs-built_in">alias</span> jan=<span class="hljs-string">'cal -m 01'</span>
<span class="hljs-built_in">alias</span> feb=<span class="hljs-string">'cal -m 02'</span>
<span class="hljs-built_in">alias</span> mar=<span class="hljs-string">'cal -m 03'</span>
<span class="hljs-built_in">alias</span> apr=<span class="hljs-string">'cal -m 04'</span>
<span class="hljs-built_in">alias</span> may=<span class="hljs-string">'cal -m 05'</span>
<span class="hljs-built_in">alias</span> jun=<span class="hljs-string">'cal -m 06'</span>
<span class="hljs-built_in">alias</span> jul=<span class="hljs-string">'cal -m 07'</span>
<span class="hljs-built_in">alias</span> aug=<span class="hljs-string">'cal -m 08'</span>
<span class="hljs-built_in">alias</span> sep=<span class="hljs-string">'cal -m 09'</span>
<span class="hljs-built_in">alias</span> oct=<span class="hljs-string">'cal -m 10'</span>
<span class="hljs-built_in">alias</span> nov=<span class="hljs-string">'cal -m 11'</span>
<span class="hljs-built_in">alias</span> dec=<span class="hljs-string">'cal -m 12'</span>

<span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">hg</span></span>() {
    <span class="hljs-built_in">history</span> | grep <span class="hljs-string">"<span class="hljs-variable">$1</span>"</span>;
}

<span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">find_largest_files</span></span>() {
    du -h -x -s -- * | sort -r -h | head -20;
}

<span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">git_branch</span></span>() {
    <span class="hljs-keyword">if</span> [ -d .git ] ; <span class="hljs-keyword">then</span>
        <span class="hljs-built_in">printf</span> <span class="hljs-string">"%s"</span> <span class="hljs-string">"(<span class="hljs-subst">$(git branch 2&gt; /dev/null | awk '/\*/{print $2}')</span>)"</span>;
    <span class="hljs-keyword">fi</span>
}

<span class="hljs-comment"># Set the prompt.</span>
<span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">bash_prompt</span></span>(){
    PS1=<span class="hljs-string">'${debian_chroot:+($debian_chroot)}'</span><span class="hljs-variable">${blu}</span><span class="hljs-string">'$(git_branch)'</span><span class="hljs-variable">${pur}</span><span class="hljs-string">' \W'</span><span class="hljs-variable">${grn}</span><span class="hljs-string">' \$ '</span><span class="hljs-variable">${clr}</span>
}

bash_prompt

<span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">git_init</span></span>() {
    <span class="hljs-keyword">if</span> [ -z <span class="hljs-string">"<span class="hljs-variable">$1</span>"</span> ]; <span class="hljs-keyword">then</span>
        <span class="hljs-built_in">printf</span> <span class="hljs-string">"%s\n"</span> <span class="hljs-string">"Please provide a directory name."</span>;
    <span class="hljs-keyword">else</span>
        mkdir <span class="hljs-string">"<span class="hljs-variable">$1</span>"</span>;
        <span class="hljs-built_in">builtin</span> <span class="hljs-built_in">cd</span> <span class="hljs-string">"<span class="hljs-variable">$1</span>"</span>;
        <span class="hljs-built_in">pwd</span>;
        git init;
        touch readme.md .gitignore LICENSE;
        <span class="hljs-built_in">echo</span> <span class="hljs-string">"# <span class="hljs-subst">$(basename $PWD)</span>"</span> &gt;&gt; readme.md
    <span class="hljs-keyword">fi</span>
}

<span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">weather_report</span></span>() {

    <span class="hljs-built_in">local</span> response=$(curl --silent <span class="hljs-string">'https://api.openweathermap.org/data/2.5/weather?id=5128581&amp;units=imperial&amp;appid=&lt;YOUR_API_KEY&gt;'</span>) 

    <span class="hljs-built_in">local</span> status=$(<span class="hljs-built_in">echo</span> <span class="hljs-variable">$response</span> | jq -r <span class="hljs-string">'.cod'</span>)

    <span class="hljs-keyword">case</span> <span class="hljs-variable">$status</span> <span class="hljs-keyword">in</span>

        200) <span class="hljs-built_in">printf</span> <span class="hljs-string">"Location: %s %s\n"</span> <span class="hljs-string">"<span class="hljs-subst">$(echo $response | jq '.name')</span> <span class="hljs-subst">$(echo $response | jq '.sys.country')</span>"</span>  
             <span class="hljs-built_in">printf</span> <span class="hljs-string">"Forecast: %s\n"</span> <span class="hljs-string">"<span class="hljs-subst">$(echo $response | jq '.weather[].description')</span>"</span> 
             <span class="hljs-built_in">printf</span> <span class="hljs-string">"Temperature: %.1f°F\n"</span> <span class="hljs-string">"<span class="hljs-subst">$(echo $response | jq '.main.temp')</span>"</span> 
             <span class="hljs-built_in">printf</span> <span class="hljs-string">"Temp Min: %.1f°F\n"</span> <span class="hljs-string">"<span class="hljs-subst">$(echo $response | jq '.main.temp_min')</span>"</span> 
             <span class="hljs-built_in">printf</span> <span class="hljs-string">"Temp Max: %.1f°F\n"</span> <span class="hljs-string">"<span class="hljs-subst">$(echo $response | jq '.main.temp_max')</span>"</span> 
            ;;
        401) <span class="hljs-built_in">echo</span> <span class="hljs-string">"401 error"</span>
            ;;
        *) <span class="hljs-built_in">echo</span> <span class="hljs-string">"error"</span>
            ;;

    <span class="hljs-keyword">esac</span>

}

clear

<span class="hljs-built_in">printf</span> <span class="hljs-string">"\n"</span>
<span class="hljs-built_in">printf</span> <span class="hljs-string">"   %s\n"</span> <span class="hljs-string">"IP ADDR: <span class="hljs-subst">$(curl ifconfig.me)</span>"</span>
<span class="hljs-built_in">printf</span> <span class="hljs-string">"   %s\n"</span> <span class="hljs-string">"USER: <span class="hljs-subst">$(echo $USER)</span>"</span>
<span class="hljs-built_in">printf</span> <span class="hljs-string">"   %s\n"</span> <span class="hljs-string">"DATE: <span class="hljs-subst">$(date)</span>"</span>
<span class="hljs-built_in">printf</span> <span class="hljs-string">"   %s\n"</span> <span class="hljs-string">"UPTIME: <span class="hljs-subst">$(uptime -p)</span>"</span>
<span class="hljs-built_in">printf</span> <span class="hljs-string">"   %s\n"</span> <span class="hljs-string">"HOSTNAME: <span class="hljs-subst">$(hostname -f)</span>"</span>
<span class="hljs-built_in">printf</span> <span class="hljs-string">"   %s\n"</span> <span class="hljs-string">"CPU: <span class="hljs-subst">$(awk -F: '/model name/{print $2}' | head -1)</span>"</span>
<span class="hljs-built_in">printf</span> <span class="hljs-string">"   %s\n"</span> <span class="hljs-string">"KERNEL: <span class="hljs-subst">$(uname -rms)</span>"</span>
<span class="hljs-built_in">printf</span> <span class="hljs-string">"   %s\n"</span> <span class="hljs-string">"PACKAGES: <span class="hljs-subst">$(dpkg --get-selections | wc -l)</span>"</span>
<span class="hljs-built_in">printf</span> <span class="hljs-string">"   %s\n"</span> <span class="hljs-string">"RESOLUTION: <span class="hljs-subst">$(xrandr | awk '/\*/{printf $1<span class="hljs-string">" "</span>}')</span>"</span>
<span class="hljs-built_in">printf</span> <span class="hljs-string">"   %s\n"</span> <span class="hljs-string">"MEMORY: <span class="hljs-subst">$(free -m -h | awk '/Mem/{print $3<span class="hljs-string">"/"</span>$2}')</span>"</span>
<span class="hljs-built_in">printf</span> <span class="hljs-string">"\n"</span>
</code></pre>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this article you learned how to configure various .bashrc options, aliases, functions, and more to greatly improve your workflow and increase your productivity.</p>
<p>Follow me on <a target="_blank" href="https://github.com/brandon-wallace">Github</a> | <a target="_blank" href="https://dev.to/brandonwallace">Dev.to</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ The Linux Command Handbook – Learn Linux Commands for Beginners ]]>
                </title>
                <description>
                    <![CDATA[ This Linux Command Handbook will cover 60 core Bash commands you will need as a developer. Each command includes example code and tips for when to use it. This Linux Command Handbook follows the 80/20 rule: you'll learn 80% of a topic in around 20% o... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/the-linux-commands-handbook/</link>
                <guid isPermaLink="false">66bb5aadb6e566d0c2aea60f</guid>
                
                    <category>
                        <![CDATA[ Linux ]]>
                    </category>
                
                    <category>
                        <![CDATA[ unix ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Flavio Copes ]]>
                </dc:creator>
                <pubDate>Tue, 03 Nov 2020 21:24:38 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/10/cover-1.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>This Linux Command Handbook will cover 60 core Bash commands you will need as a developer. Each command includes example code and tips for when to use it.</p>
<p>This Linux Command Handbook follows the 80/20 rule: you'll learn 80% of a topic in around 20% of the time you spend studying it.</p>
<p>I find that this approach gives you a well-rounded overview. </p>
<p>This handbook does not try to cover everything under the sun related to Linux and its commands. It focuses on the small core commands that you will use the 80% or 90% of the time, and tries to simplify the usage of the more complex ones.</p>
<p>All these commands work on Linux, macOS, WSL, and anywhere you have a UNIX environment.</p>
<p>I hope the contents of this handbook will help you achieve what you want: <strong>getting comfortable with Linux</strong>.</p>
<p>You can bookmark this page in your browser so you can reference this handbook in the future.</p>
<p>And you can <a target="_blank" href="https://flaviocopes.com/page/linux-commands-handbook/">download this handbook in PDF / ePUB / Mobi format for free</a>.</p>
<p>Enjoy!</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><a class="post-section-overview" href="#heading-introduction-to-linux-and-shells">Introduction to Linux and shells</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-man-command">The Linux <code>man</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-ls-command">The Linux <code>ls</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-cd-command">The Linux <code>cd</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-pwd-command">The Linux <code>pwd</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-mkdir-command">The Linux <code>mkdir</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-rmdir-command">The Linux <code>rmdir</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-mv-command">The Linux <code>mv</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-cp-command">The Linux <code>cp</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-open-command">The Linux <code>open</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-touch-command">The Linux <code>touch</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-find-command">The Linux <code>find</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-ln-command">The Linux <code>ln</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-gzip-command">The Linux <code>gzip</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-gunzip-command">The Linux <code>gunzip</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-tar-command">The Linux <code>tar</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-alias-command">The Linux <code>alias</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-cat-command">The Linux <code>cat</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-less-command">The Linux <code>less</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-tail-command">The Linux <code>tail</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-wc-command">The Linux <code>wc</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-grep-command">The Linux <code>grep</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-sort-command">The Linux <code>sort</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-uniq-command">The Linux <code>uniq</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-diff-command">The Linux <code>diff</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-echo-command">The Linux <code>echo</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-chown-command">The Linux <code>chown</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-chmod-command">The Linux <code>chmod</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-umask-command">The Linux <code>umask</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-du-command">The Linux <code>du</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-df-command">The Linux <code>df</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-basename-command">The Linux <code>basename</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-dirname-command">The Linux <code>dirname</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-ps-command">The Linux <code>ps</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-top-command">The Linux <code>top</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-kill-command">The Linux <code>kill</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-killall-command">The Linux <code>killall</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-jobs-command">The Linux <code>jobs</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-bg-command">The Linux <code>bg</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-fg-command">The Linux <code>fg</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-type-command">The Linux <code>type</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-which-command">The Linux <code>which</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-nohup-command">The Linux <code>nohup</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-xargs-command">The Linux <code>xargs</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-vim-editor-command">The Linux <code>vim</code> editor command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-emacs-editor-command">The Linux <code>emacs</code> editor command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-nano-editor-command">The Linux <code>nano</code> editor command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-whoami-command">The Linux <code>whoami</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-who-command">The Linux <code>who</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-su-command">The Linux <code>su</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-sudo-command">The Linux <code>sudo</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-passwd-command">The Linux <code>passwd</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-ping-command">The Linux <code>ping</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-traceroute-command">The Linux <code>traceroute</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-clear-command">The Linux <code>clear</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-history-command">The Linux <code>history</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-export-command">The Linux <code>export</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-crontab-command">The Linux <code>crontab</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-uname-command">The Linux <code>uname</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-env-command">The Linux <code>env</code> command</a></li>
<li><a class="post-section-overview" href="#heading-the-linux-printenv-command">The Linux <code>printenv</code> command</a></li>
<li><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></li>
</ul>
<h2 id="heading-introduction-to-linux-and-shells">Introduction to Linux and shells</h2>
<h3 id="heading-what-is-linux">What is Linux?</h3>
<p>Linux is an operating system, like macOS or Windows.</p>
<p>It is also the most popular Open Source operating system, and it gives you a lot of freedom.</p>
<p>It powers the vast majority of the servers that compose the Internet. It's the base upon which everything is built. But not just that. Android is based on (a modified version of) Linux.</p>
<p>The Linux "core" (called a <em>kernel</em>) was born in 1991 in Finland, and it has come a really long way from its humble beginnings. It went on to be the kernel of the GNU Operating System, creating the duo GNU/Linux.</p>
<p>There's one thing about Linux that corporations like Microsoft, Apple, and Google will never be able to offer: the freedom to do whatever you want with your computer.</p>
<p>They're actually going in the opposite direction, building walled gardens, especially on the mobile side.</p>
<p>Linux is the ultimate freedom. </p>
<p>It is developed by volunteers, some paid by companies that rely on it, some independently. But there's no single commercial company that can dictate what goes into Linux, or the project's priorities.</p>
<p>You can also use Linux as your day to day computer. I use macOS because I really enjoy the applications and design (and I also used to be an iOS and Mac apps developer). But before using macOS I used Linux as my main computer Operating System.</p>
<p>No one can dictate which apps you can run, or "call home" with apps that track you, your position, and more.</p>
<p>Linux is also special because there's not just "one Linux", like is the case with Windows or macOS. Instead, we have <strong>distributions</strong>.</p>
<p>A "distro" is made by a company or organization and packages the Linux core with additional programs and tooling. </p>
<p>For example you have Debian, Red Hat, and Ubuntu, probably the most popular distributions. </p>
<p>But many, many more exist. You can create your own distribution, too. But most likely you'll use a popular one that has lots of users and a community of people around it. This lets you do what you need to do without losing too much time reinventing the wheel and figuring out answers to common problems.</p>
<p>Some desktop computers and laptops ship with Linux preinstalled. Or you can install it on your Windows-based computer, or on a Mac.</p>
<p>But you don't need to disrupt your existing computer just to get an idea of how Linux works. </p>
<p>I don't have a Linux computer.</p>
<p>If you use a Mac, you just need to know that under the hood macOS is a UNIX Operating System. It shares a lot of the same ideas and software that a GNU/Linux system uses, because GNU/Linux is a free alternative to UNIX.</p>
<blockquote>
<p><a target="_blank" href="https://en.wikipedia.org/wiki/Unix">UNIX</a> is an umbrella term that groups many operating systems used in big corporations and institutions, starting from the 70's</p>
</blockquote>
<p>The macOS terminal gives you access to the same exact commands I'll describe in the rest of this handbook.</p>
<p>Microsoft has an official <a target="_blank" href="https://docs.microsoft.com/en-us/windows/wsl/install-win10">Windows Subsystem for Linux</a> which you can (and should!) install on Windows. This will give you the ability to run Linux in a very easy way on your PC.</p>
<p>But the vast majority of the time you will run a Linux computer in the cloud via a VPS (Virtual Private Server) like DigitalOcean.</p>
<h3 id="heading-what-is-a-linux-shell">What is a Linux shell?</h3>
<p>A shell is a command interpreter that exposes an interface to the user to work with the underlying operating system.</p>
<p>It allows you to execute operations using text and commands, and it provides users advanced features like being able to create scripts.</p>
<p>This is important: shells let you perform things in a more optimized way than a GUI (Graphical User Interface) could ever possibly let you do. Command line tools can offer many different configuration options without being too complex to use.</p>
<p>There are many different kind of shells. This post focuses on Unix shells, the ones that you will find commonly on Linux and macOS computers.</p>
<p>Many different kind of shells were created for those systems over time, and a few of them dominate the space: Bash, Csh, Zsh, Fish and many more!</p>
<p>All shells originate from the Bourne Shell, called <code>sh</code>. "Bourne" because its creator was Steve Bourne.</p>
<p>Bash means <em>Bourne-again shell</em>. <code>sh</code> was proprietary and not open source, and Bash was created in 1989 to create a free alternative for the GNU project and the Free Software Foundation. Since projects had to pay to use the Bourne shell, Bash became very popular.</p>
<p>If you use a Mac, try opening your Mac terminal. By default it runs ZSH (or, pre-Catalina, Bash).</p>
<p>You can set up your system to run any kind of shell – for example I use the Fish shell.</p>
<p>Each single shell has its own unique features and advanced usage, but they all share a common functionality: they can let you execute programs, and they can be programmed.</p>
<p>In the rest of this handbook we'll see in detail the most common commands you will use.</p>
<h2 id="heading-the-linux-man-command">The Linux <code>man</code> command</h2>
<p>The first command I'll introduce will help you understand all the other commands.</p>
<p>Every time I don't know how to use a command, I type <code>man &lt;command&gt;</code> to get the manual:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-07-04-at-18.42.40.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>This is a man (from <strong>manual</strong>) page. Man pages are an essential tool to learn as a developer. They contain so much information that sometimes it's almost too much.<br>The above screenshot is just 1 of 14 screens of explanation for the <code>ls</code> command.</p>
<p>Most of the time when I need to learn a command quickly I use this site called <strong>tldr pages</strong>: <a target="_blank" href="https://tldr.sh/">https://tldr.sh</a>. It's a command you can install, which you then run like this: <code>tldr &lt;command&gt;</code>. It gives you a very quick overview of a command, with some handy examples of common usage scenarios:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-07-at-07.35.41.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>This is not a substitute for <code>man</code>, but a handy tool to avoid losing yourself in the huge amount of information present in a <code>man</code> page. Then you can use the <code>man</code> page to explore all the different options and parameters you can use on a command.</p>
<h2 id="heading-the-linux-ls-command">The Linux <code>ls</code> command</h2>
<p>Inside a folder you can list all the files that the folder contains using the <code>ls</code> command:</p>
<pre><code class="lang-bash">ls
</code></pre>
<p>If you add a folder name or path, it will print that folder's contents:</p>
<pre><code class="lang-bash">ls /bin
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screenshot-2019-02-09-at-18.50.14.png" alt="Screenshot-2019-02-09-at-18.50.14" width="600" height="400" loading="lazy"></p>
<p><code>ls</code> accepts a lot of options. One of my favorite combinations is <code>-al</code>. Try it:</p>
<pre><code class="lang-bash">ls -al /bin
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screenshot-2019-02-09-at-18.49.52.png" alt="Screenshot-2019-02-09-at-18.49.52" width="600" height="400" loading="lazy"></p>
<p>Compared to the plain <code>ls</code> command, this returns much more information.</p>
<p>You have, from left to right:</p>
<ul>
<li>the file permissions (and if your system supports ACLs, you get an ACL flag as well)</li>
<li>the number of links to that file</li>
<li>the owner of the file</li>
<li>the group of the file</li>
<li>the file size in bytes</li>
<li>the file's last modified datetime</li>
<li>the file name</li>
</ul>
<p>This set of data is generated by the <code>l</code> option. The <code>a</code> option instead also shows the hidden files.</p>
<p>Hidden files are files that start with a dot (<code>.</code>).</p>
<h2 id="heading-the-linux-cd-command">The Linux <code>cd</code> command</h2>
<p>Once you have a folder, you can move into it using the <code>cd</code> command. <code>cd</code> means <strong>c</strong>hange <strong>d</strong>irectory. You invoke it specifying a folder to move into. You can specify a folder name, or an entire path.</p>
<p>Example:</p>
<pre><code class="lang-bash">mkdir fruits
<span class="hljs-built_in">cd</span> fruits
</code></pre>
<p>Now you are in the <code>fruits</code> folder.</p>
<p>You can use the <code>..</code> special path to indicate the parent folder:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">cd</span> .. <span class="hljs-comment">#back to the home folder</span>
</code></pre>
<p>The # character indicates the start of the comment, which lasts for the entire line after it's found.</p>
<p>You can use it to form a path:</p>
<pre><code class="lang-bash">mkdir fruits
mkdir cars
<span class="hljs-built_in">cd</span> fruits
<span class="hljs-built_in">cd</span> ../cars
</code></pre>
<p>There is another special path indicator which is <code>.</code>, and indicates the <strong>current</strong> folder.</p>
<p>You can also use absolute paths, which start from the root folder <code>/</code>:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">cd</span> /etc
</code></pre>
<h2 id="heading-the-linux-pwd-command">The Linux <code>pwd</code> command</h2>
<p>Whenever you feel lost in the filesystem, call the <code>pwd</code> command to know where you are:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">pwd</span>
</code></pre>
<p>It will print the current folder path.</p>
<h2 id="heading-the-linux-mkdir-command">The Linux <code>mkdir</code> command</h2>
<p>You create folders using the <code>mkdir</code> command:</p>
<pre><code class="lang-bash">mkdir fruits
</code></pre>
<p>You can create multiple folders with one command:</p>
<pre><code class="lang-bash">mkdir dogs cars
</code></pre>
<p>You can also create multiple nested folders by adding the <code>-p</code> option:</p>
<pre><code class="lang-bash">mkdir -p fruits/apples
</code></pre>
<p>Options in UNIX commands commonly take this form. You add them right after the command name, and they change how the command behaves. You can often combine multiple options, too.</p>
<p>You can find which options a command supports by typing <code>man &lt;commandname&gt;</code>. Try now with <code>man mkdir</code> for example (press the <code>q</code> key to esc the man page). Man pages are the amazing built-in help for UNIX.</p>
<h2 id="heading-the-linux-rmdir-command">The Linux <code>rmdir</code> command</h2>
<p>Just as you can create a folder using <code>mkdir</code>, you can delete a folder using <code>rmdir</code>:</p>
<pre><code class="lang-bash">mkdir fruits
rmdir fruits
</code></pre>
<p>You can also delete multiple folders at once:</p>
<pre><code class="lang-bash">mkdir fruits cars
rmdir fruits cars
</code></pre>
<p>The folder you delete must be empty.</p>
<p>To delete folders with files in them, we'll use the more generic <code>rm</code> command which deletes files and folders, using the <code>-rf</code> option:</p>
<pre><code class="lang-bash">rm -rf fruits cars
</code></pre>
<p>Be careful as this command does not ask for confirmation and it will immediately remove anything you ask it to remove.</p>
<p>There is no <strong>bin</strong> when removing files from the command line, and recovering lost files can be hard.</p>
<h2 id="heading-the-linux-mv-command">The Linux <code>mv</code> command</h2>
<p>Once you have a file, you can move it around using the <code>mv</code> command. You specify the file current path, and its new path:</p>
<pre><code class="lang-bash">touch <span class="hljs-built_in">test</span>
mv pear new_pear
</code></pre>
<p>The <code>pear</code> file is now moved to <code>new_pear</code>. This is how you <strong>rename</strong> files and folders.</p>
<p>If the last parameter is a folder, the file located at the first parameter path is going to be moved into that folder. In this case, you can specify a list of files and they will all be moved in the folder path identified by the last parameter:</p>
<pre><code class="lang-bash">touch pear
touch apple
mkdir fruits
mv pear apple fruits <span class="hljs-comment">#pear and apple moved to the fruits folder</span>
</code></pre>
<h2 id="heading-the-linux-cp-command">The Linux <code>cp</code> command</h2>
<p>You can copy a file using the <code>cp</code> command:</p>
<pre><code class="lang-bash">touch <span class="hljs-built_in">test</span>
cp apple another_apple
</code></pre>
<p>To copy folders you need to add the <code>-r</code> option to recursively copy the whole folder contents:</p>
<pre><code class="lang-bash">mkdir fruits
cp -r fruits cars
</code></pre>
<h2 id="heading-the-linux-open-command">The Linux <code>open</code> command</h2>
<p>The <code>open</code> command lets you open a file using this syntax:</p>
<pre><code class="lang-bash">open &lt;filename&gt;
</code></pre>
<p>You can also open a directory, which on macOS opens the Finder app with the current directory open:</p>
<pre><code class="lang-bash">open &lt;directory name&gt;
</code></pre>
<p>I use it all the time to open the current directory:</p>
<pre><code class="lang-bash">open .
</code></pre>
<blockquote>
<p>The special <code>.</code> symbol points to the current directory, as <code>..</code> points to the parent directory</p>
</blockquote>
<p>The same command can also be be used to run an application:</p>
<pre><code class="lang-bash">open &lt;application name&gt;
</code></pre>
<h2 id="heading-the-linux-touch-command">The Linux <code>touch</code> command</h2>
<p>You can create an empty file using the <code>touch</code> command:</p>
<pre><code class="lang-bash">touch apple
</code></pre>
<p>If the file already exists, it opens the file in write mode, and the timestamp of the file is updated.</p>
<h2 id="heading-the-linux-find-command">The Linux <code>find</code> command</h2>
<p>The <code>find</code> command can be used to find files or folders matching a particular search pattern. It searches recursively.</p>
<p>Let's learn how to use it by example.</p>
<p>Find all the files under the current tree that have the <code>.js</code> extension and print the relative path of each file that matches:</p>
<pre><code class="lang-bash">find . -name <span class="hljs-string">'*.js'</span>
</code></pre>
<p>It's important to use quotes around special characters like <code>*</code> to avoid the shell interpreting them.</p>
<p>Find directories under the current tree matching the name "src":</p>
<pre><code class="lang-bash">find . -<span class="hljs-built_in">type</span> d -name src
</code></pre>
<p>Use <code>-type f</code> to search only files, or <code>-type l</code> to only search symbolic links.</p>
<p><code>-name</code> is case sensitive. use <code>-iname</code> to perform a case-insensitive search.</p>
<p>You can search under multiple root trees:</p>
<pre><code class="lang-bash">find folder1 folder2 -name filename.txt
</code></pre>
<p>Find directories under the current tree matching the name "node_modules" or 'public':</p>
<pre><code class="lang-bash">find . -<span class="hljs-built_in">type</span> d -name node_modules -or -name public
</code></pre>
<p>You can also exclude a path using <code>-not -path</code>:</p>
<pre><code class="lang-bash">find . -<span class="hljs-built_in">type</span> d -name <span class="hljs-string">'*.md'</span> -not -path <span class="hljs-string">'node_modules/*'</span>
</code></pre>
<p>You can search files that have more than 100 characters (bytes) in them:</p>
<pre><code class="lang-bash">find . -<span class="hljs-built_in">type</span> f -size +100c
</code></pre>
<p>Search files bigger than 100KB but smaller than 1MB:</p>
<pre><code class="lang-bash">find . -<span class="hljs-built_in">type</span> f -size +100k -size -1M
</code></pre>
<p>Search files edited more than 3 days ago:</p>
<pre><code class="lang-bash">find . -<span class="hljs-built_in">type</span> f -mtime +3
</code></pre>
<p>Search files edited in the last 24 hours:</p>
<pre><code class="lang-bash">find . -<span class="hljs-built_in">type</span> f -mtime -1
</code></pre>
<p>You can delete all the files matching a search by adding the <code>-delete</code> option. This deletes all the files edited in the last 24 hours:</p>
<pre><code class="lang-bash">find . -<span class="hljs-built_in">type</span> f -mtime -1 -delete
</code></pre>
<p>You can execute a command on each result of the search. In this example we run <code>cat</code> to print the file content:</p>
<pre><code class="lang-bash">find . -<span class="hljs-built_in">type</span> f -<span class="hljs-built_in">exec</span> cat {} \;
</code></pre>
<p>Notice the terminating <code>\;</code>. <code>{}</code> is filled with the file name at execution time.</p>
<h2 id="heading-the-linux-ln-command">The Linux <code>ln</code> command</h2>
<p>The <code>ln</code> command is part of the Linux file system commands.</p>
<p>It's used to create links. What is a link? It's like a pointer to another file, or a file that points to another file. You might be familiar with Windows shortcuts. They're similar.</p>
<p>We have 2 types of links: <strong>hard links</strong> and <strong>soft links</strong>.</p>
<h4 id="heading-hard-links">Hard links</h4>
<p>Hard links are rarely used. They have a few limitations: you can't link to directories, and you can't link to external filesystems (disks).</p>
<p>A hard link is created using the following syntax:</p>
<pre><code class="lang-bash">ln &lt;original&gt; &lt;link&gt;
</code></pre>
<p>For example, say you have a file called recipes.txt. You can create a hard link to it using:</p>
<pre><code class="lang-bash">ln recipes.txt newrecipes.txt
</code></pre>
<p>The new hard link you created is indistinguishable from a regular file:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-02-at-11.26.21.png" alt="Screen-Shot-2020-09-02-at-11.26.21" width="600" height="400" loading="lazy"></p>
<p>Now any time you edit any of those files, the content will be updated for both.</p>
<p>If you delete the original file, the link will still contain the original file content, as that's not removed until there is one hard link pointing to it.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-02-at-11.26.07.png" alt="Screen-Shot-2020-09-02-at-11.26.07" width="600" height="400" loading="lazy"></p>
<h4 id="heading-soft-links">Soft links</h4>
<p>Soft links are different. They are more powerful as you can link to other filesystems and to directories. But keep in mind that when the original is removed, the link will be broken.</p>
<p>You create soft links using the <code>-s</code> option of <code>ln</code>:</p>
<pre><code class="lang-bash">ln -s &lt;original&gt; &lt;link&gt;
</code></pre>
<p>For example, say you have a file called recipes.txt. You can create a soft link to it using:</p>
<pre><code class="lang-bash">ln -s recipes.txt newrecipes.txt
</code></pre>
<p>In this case you can see there's a special <code>l</code> flag when you list the file using <code>ls -al</code>. The file name has a <code>@</code> at the end, and it's also colored differently if you have colors enabled:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-02-at-11.27.18.png" alt="Screen-Shot-2020-09-02-at-11.27.18" width="600" height="400" loading="lazy">
Now if you delete the original file, the links will be broken, and the shell will tell you "No such file or directory" if you try to access it:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-02-at-11.27.03.png" alt="Screen-Shot-2020-09-02-at-11.27.03" width="600" height="400" loading="lazy"></p>
<h2 id="heading-the-linux-gzip-command">The Linux <code>gzip</code> command</h2>
<p>You can compress a file using the gzip compression protocol named <a target="_blank" href="https://en.wikipedia.org/wiki/LZ77_and_LZ78">LZ77</a> using the <code>gzip</code> command.</p>
<p>Here's the simplest usage:</p>
<pre><code class="lang-bash">gzip filename
</code></pre>
<p>This will compress the file, and append a <code>.gz</code> extension to it. The original file is deleted. </p>
<p>To prevent this, you can use the <code>-c</code> option and use output redirection to write the output to the <code>filename.gz</code> file:</p>
<pre><code class="lang-bash">gzip -c filename &gt; filename.gz
</code></pre>
<blockquote>
<p>The <code>-c</code> option specifies that the output will go to the standard output stream, leaving the original file intact.</p>
</blockquote>
<p>Or you can use the <code>-k</code> option:</p>
<pre><code class="lang-bash">gzip -k filename
</code></pre>
<p>There are various levels of compression. The more the compression, the longer it will take to compress (and decompress). Levels range from 1 (fastest, worst compression) to 9 (slowest, better compression), and the default is 6.</p>
<p>You can choose a specific level with the <code>-&lt;NUMBER&gt;</code> option:</p>
<pre><code class="lang-bash">gzip -1 filename
</code></pre>
<p>You can compress multiple files by listing them:</p>
<pre><code class="lang-bash">gzip filename1 filename2
</code></pre>
<p>You can compress all the files in a directory, recursively, using the <code>-r</code> option:</p>
<pre><code class="lang-bash">gzip -r a_folder
</code></pre>
<p>The <code>-v</code> option prints the compression percentage information. Here's an example of it being used along with the <code>-k</code> (keep) option:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-09-at-15.55.42.png" alt="Screen-Shot-2020-09-09-at-15.55.42" width="600" height="400" loading="lazy">
<code>gzip</code> can also be used to decompress a file, using the <code>-d</code> option:</p>
<pre><code class="lang-bash">gzip -d filename.gz
</code></pre>
<h2 id="heading-the-linux-gunzip-command">The Linux <code>gunzip</code> command</h2>
<p>The <code>gunzip</code> command is basically equivalent to the <code>gzip</code> command, except the <code>-d</code> option is always enabled by default.</p>
<p>The command can be invoked in this way:</p>
<pre><code class="lang-bash">gunzip filename.gz
</code></pre>
<p>This will gunzip and will remove the <code>.gz</code> extension, putting the result in the <code>filename</code> file. If that file exists, it will overwrite that.</p>
<p>You can extract to a different filename using output redirection using the <code>-c</code> option:</p>
<pre><code class="lang-bash">gunzip -c filename.gz &gt; anotherfilename
</code></pre>
<h2 id="heading-the-linux-tar-command">The Linux <code>tar</code> command</h2>
<p>The <code>tar</code> command is used to create an archive, grouping multiple files in a single file.</p>
<p>Its name comes from the past and means <em>tape archive</em> (back when archives were stored on tapes).</p>
<p>This command creates an archive named <code>archive.tar</code> with the content of <code>file1</code> and <code>file2</code>:</p>
<pre><code class="lang-bash">tar -cf archive.tar file1 file2
</code></pre>
<blockquote>
<p>The <code>c</code> option stands for <em>create</em>. The <code>f</code> option is used to write to file the archive.</p>
</blockquote>
<p>To extract files from an archive in the current folder, use:</p>
<pre><code class="lang-bash">tar -xf archive.tar
</code></pre>
<blockquote>
<p>the <code>x</code> option stands for <em>extract</em>.</p>
</blockquote>
<p>And to extract them to a specific directory, use:</p>
<pre><code class="lang-bash">tar -xf archive.tar -C directory
</code></pre>
<p>You can also just list the files contained in an archive:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-09-at-16.56.33.png" alt="Screen-Shot-2020-09-09-at-16.56.33" width="600" height="400" loading="lazy">
<code>tar</code> is often used to create a <strong>compressed archive</strong>, gzipping the archive.</p>
<p>This is done using the <code>z</code> option:</p>
<pre><code class="lang-bash">tar -czf archive.tar.gz file1 file2
</code></pre>
<p>This is just like creating a tar archive, and then running <code>gzip</code> on it.</p>
<p>To unarchive a gzipped archive, you can use <code>gunzip</code>, or <code>gzip -d</code>, and then unarchive it. But <code>tar -xf</code> will recognize it's a gzipped archive, and do it for you:</p>
<pre><code class="lang-bash">tar -xf archive.tar.gz
</code></pre>
<h2 id="heading-the-linux-alias-command">The Linux <code>alias</code> command</h2>
<p>It's common to always run a program with a set of options that you like using.</p>
<p>For example, take the <code>ls</code> command. By default it prints very little information:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-15.21.00.png" alt="Screen-Shot-2020-09-03-at-15.21.00" width="600" height="400" loading="lazy"></p>
<p>But if you use the <code>-al</code> option it will print something more useful, including the file modification date, the size, the owner, and the permissions. It will also list hidden files (files starting with a <code>.</code>):</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-15.21.08.png" alt="Screen-Shot-2020-09-03-at-15.21.08" width="600" height="400" loading="lazy"></p>
<p>You can create a new command, for example I like to call it <code>ll</code>, that is an alias to <code>ls -al</code>.</p>
<p>You do it like this:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">alias</span> ll=<span class="hljs-string">'ls -al'</span>
</code></pre>
<p>Once you do, you can call <code>ll</code> just like it was a regular UNIX command:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-15.22.51.png" alt="Screen-Shot-2020-09-03-at-15.22.51" width="600" height="400" loading="lazy"></p>
<p>Now calling <code>alias</code> without any option will list the aliases defined:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-15.30.19.png" alt="Screen-Shot-2020-09-03-at-15.30.19" width="600" height="400" loading="lazy">
The alias will work until the terminal session is closed.</p>
<p>To make it permanent, you need to add it to the shell configuration. This could be <code>~/.bashrc</code> or <code>~/.profile</code> or <code>~/.bash_profile</code> if you use the Bash shell, depending on the use case.</p>
<p>Be careful with quotes if you have variables in the command: if you use double quotes, the variable is resolved at definition time. If you use use single quotes, it's resolved at invocation time. Those 2 are different:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">alias</span> lsthis=<span class="hljs-string">"ls <span class="hljs-variable">$PWD</span>"</span>
<span class="hljs-built_in">alias</span> lscurrent=<span class="hljs-string">'ls $PWD'</span>
</code></pre>
<p>\$PWD refers to the current folder the shell is in. If you now navigate away to a new folder, <code>lscurrent</code> lists the files in the new folder, whereas <code>lsthis</code> still lists the files in the folder where you were when you defined the alias.</p>
<h2 id="heading-the-linux-cat-command">The Linux <code>cat</code> command</h2>
<p>Similar to <a target="_blank" href="https://www.freecodecamp.org/news/unix-command-tail/"><code>tail</code></a> in some ways, we have <code>cat</code>. Except <code>cat</code> can also add content to a file, and this makes it super powerful.</p>
<p>In its simplest usage, <code>cat</code> prints a file's content to the standard output:</p>
<pre><code class="lang-bash">cat file
</code></pre>
<p>You can print the content of multiple files:</p>
<pre><code class="lang-bash">cat file1 file2
</code></pre>
<p>and using the output redirection operator <code>&gt;</code> you can concatenate the content of multiple files into a new file:</p>
<pre><code class="lang-bash">cat file1 file2 &gt; file3
</code></pre>
<p>Using <code>&gt;&gt;</code> you can append the content of multiple files into a new file, creating it if it does not exist:</p>
<pre><code class="lang-bash">cat file1 file2 &gt;&gt; file3
</code></pre>
<p>When you're looking at source code files it's helpful to see the line numbers. You can have <code>cat</code> print them using the <code>-n</code> option:</p>
<pre><code class="lang-bash">cat -n file1
</code></pre>
<p>You can only add a number to non-blank lines using <code>-b</code>, or you can also remove all the multiple empty lines using <code>-s</code>.</p>
<p><code>cat</code> is often used in combination with the pipe operator <code>|</code> to feed a file's content as input to another command: <code>cat file1 | anothercommand</code>.</p>
<h2 id="heading-the-linux-less-command">The Linux <code>less</code> command</h2>
<p>The <code>less</code> command is one I use a lot. It shows you the content stored inside a file, in a nice and interactive UI.</p>
<p>Usage: <code>less &lt;filename&gt;</code>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screenshot-2019-02-10-at-09.11.05.png" alt="Screenshot-2019-02-10-at-09.11.05" width="600" height="400" loading="lazy"></p>
<p>Once you are inside a <code>less</code> session, you can quit by pressing <code>q</code>.</p>
<p>You can navigate the file contents using the <code>up</code> and <code>down</code> keys, or using the <code>space bar</code> and <code>b</code> to navigate page by page. You can also jump to the end of the file pressing <code>G</code> and jump back to the start by pressing <code>g</code>.</p>
<p>You can search contents inside the file by pressing <code>/</code> and typing a word to search. This searches <em>forward</em>. You can search backwards using the <code>?</code> symbol and typing a word.</p>
<p>This command just visualises the file's content. You can directly open an editor by pressing <code>v</code>. It will use the system editor, which in most cases is <code>vim</code>.</p>
<p>Pressing the <code>F</code> key enters <em>follow mode</em>, or <em>watch mode</em>. When the file is changed by someone else, like from another program, you get to see the changes <em>live</em>. </p>
<p>This doesn't happen by default, and you only see the file version at the time you opened it. You need to press <code>ctrl-C</code> to quit this mode. In this case the behaviour is similar to running the <code>tail -f &lt;filename&gt;</code> command.</p>
<p>You can open multiple files, and navigate through them using <code>:n</code> (to go to the next file) and <code>:p</code> (to go to the previous).</p>
<h2 id="heading-the-linux-tail-command">The Linux <code>tail</code> command</h2>
<p>The best use case of tail in my opinion is when called with the <code>-f</code> option. It opens the file at the end, and watches for file changes. </p>
<p>Any time there is new content in the file, it is printed in the window. This is great for watching log files, for example:</p>
<pre><code class="lang-bash">tail -f /var/<span class="hljs-built_in">log</span>/system.log
</code></pre>
<p>To exit, press <code>ctrl-C</code>.</p>
<p>You can print the last 10 lines in a file:</p>
<pre><code class="lang-bash">tail -n 10 &lt;filename&gt;
</code></pre>
<p>You can print the whole file content starting from a specific line using <code>+</code> before the line number:</p>
<pre><code class="lang-bash">tail -n +10 &lt;filename&gt;
</code></pre>
<p><code>tail</code> can do much more and as always my advice is to check <code>man tail</code>.</p>
<h2 id="heading-the-linux-wc-command">The Linux <code>wc</code> command</h2>
<p>The <code>wc</code> command gives us useful information about a file or input it receives via pipes.</p>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> <span class="hljs-built_in">test</span> &gt;&gt; test.txt
wc test.txt
1       1       5 test.txt
</code></pre>
<p>Example via pipes, we can count the output of running the <code>ls -al</code> command:</p>
<pre><code class="lang-bash">ls -al | wc
6      47     284
</code></pre>
<p>The first column returned is the number of lines. The second is the number of words. The third is the number of bytes.</p>
<p>We can tell it to just count the lines:</p>
<pre><code class="lang-bash">wc -l test.txt
</code></pre>
<p>or just the words:</p>
<pre><code class="lang-bash">wc -w test.txt
</code></pre>
<p>or just the bytes:</p>
<pre><code class="lang-bash">wc -c test.txt
</code></pre>
<p>Bytes in ASCII charsets equate to characters. But with non-ASCII charsets, the number of characters might differ because some characters might take multiple bytes (for example this happens in Unicode).</p>
<p>In this case the <code>-m</code> flag will help you get the correct value:</p>
<pre><code class="lang-bash">wc -m test.txt
</code></pre>
<h2 id="heading-the-linux-grep-command">The Linux <code>grep</code> command</h2>
<p>The <code>grep</code> command is a very useful tool. When you master it, it will help you tremendously in your day to day coding.</p>
<blockquote>
<p>If you're wondering, <code>grep</code> stands for <em>global regular expression print</em>.</p>
</blockquote>
<p>You can use <code>grep</code> to search in files, or combine it with pipes to filter the output of another command.</p>
<p>For example here's how we can find the occurences of the <code>document.getElementById</code> line in the <code>index.md</code> file:</p>
<pre><code class="lang-bash">grep -n document.getElementById index.md
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-04-at-09.42.10.png" alt="Screen-Shot-2020-09-04-at-09.42.10" width="600" height="400" loading="lazy"></p>
<p>Using the <code>-n</code> option it will show the line numbers:</p>
<pre><code class="lang-bash">grep -n document.getElementById index.md
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-04-at-09.47.04.png" alt="Screen-Shot-2020-09-04-at-09.47.04" width="600" height="400" loading="lazy"></p>
<p>One very useful thing is to tell grep to print 2 lines before and 2 lines after the matched line to give you more context. That's done using the <code>-C</code> option, which accepts a number of lines:</p>
<pre><code class="lang-bash">grep -nC 2 document.getElementById index.md
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-04-at-09.44.35.png" alt="Screen-Shot-2020-09-04-at-09.44.35" width="600" height="400" loading="lazy"></p>
<p>Search is case sensitive by default. Use the <code>-i</code> flag to make it insensitive.</p>
<p>As mentioned, you can use grep to filter the output of another command. We can replicate the same functionality as above using:</p>
<pre><code class="lang-bash">less index.md | grep -n document.getElementById
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-04-at-09.43.15.png" alt="Screen-Shot-2020-09-04-at-09.43.15" width="600" height="400" loading="lazy"></p>
<p>The search string can be a regular expression, and this makes <code>grep</code> very powerful.</p>
<p>Another thing you might find very useful is to invert the result, excluding the lines that match a particular string, using the <code>-v</code> option:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-04-at-09.42.04.png" alt="Screen-Shot-2020-09-04-at-09.42.04" width="600" height="400" loading="lazy"></p>
<h2 id="heading-the-linux-sort-command">The Linux <code>sort</code> command</h2>
<p>Suppose you have a text file which contains the names of dogs:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-07-at-07.56.28.png" alt="Screen-Shot-2020-09-07-at-07.56.28" width="600" height="400" loading="lazy"></p>
<p>This list is unordered.</p>
<p>The <code>sort</code> command helps you sort them by name:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-07-at-07.57.08.png" alt="Screen-Shot-2020-09-07-at-07.57.08" width="600" height="400" loading="lazy"></p>
<p>Use the <code>r</code> option to reverse the order:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-07-at-07.57.28.png" alt="Screen-Shot-2020-09-07-at-07.57.28" width="600" height="400" loading="lazy"></p>
<p>Sorting by default is case sensitive, and alphabetic. Use the <code>--ignore-case</code> option to sort case insensitive, and the <code>-n</code> option to sort using a numeric order.</p>
<p>If the file contains duplicate lines:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-07-at-07.59.03.png" alt="Screen-Shot-2020-09-07-at-07.59.03" width="600" height="400" loading="lazy"></p>
<p>You can use the <code>-u</code> option to remove them:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-07-at-07.59.16.png" alt="Screen-Shot-2020-09-07-at-07.59.16" width="600" height="400" loading="lazy"></p>
<p><code>sort</code> does not just work on files, as many UNIX commands do – it also works with pipes. So you can use it on the output of another command. For example you can order the files returned by <code>ls</code> with:</p>
<pre><code class="lang-bash">ls | sort
</code></pre>
<p><code>sort</code> is very powerful and has lots more options, which you can explore by calling <code>man sort</code>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-07-at-08.01.27.png" alt="Screen-Shot-2020-09-07-at-08.01.27" width="600" height="400" loading="lazy"></p>
<h2 id="heading-the-linux-uniq-command">The Linux <code>uniq</code> command</h2>
<p><code>uniq</code> is a command that helps you sort lines of text.</p>
<p>You can get those lines from a file, or using pipes from the output of another command:</p>
<pre><code class="lang-bash">uniq dogs.txt

ls | uniq
</code></pre>
<p>You need to consider this key thing: <code>uniq</code> will only detect adjacent duplicate lines.</p>
<p>This implies that you will most likely use it along with <code>sort</code>:</p>
<pre><code class="lang-bash">sort dogs.txt | uniq
</code></pre>
<p>The <code>sort</code> command has its own way to remove duplicates with the <code>-u</code> (<em>unique</em>) option. But <code>uniq</code> has more power.</p>
<p>By default it removes duplicate lines:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-07-at-08.39.35.png" alt="Screen-Shot-2020-09-07-at-08.39.35" width="600" height="400" loading="lazy"></p>
<p>You can tell it to only display duplicate lines, for example, with the <code>-d</code> option:</p>
<pre><code class="lang-bash">sort dogs.txt | uniq -d
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-07-at-08.36.50.png" alt="Screen-Shot-2020-09-07-at-08.36.50" width="600" height="400" loading="lazy"></p>
<p>You can use the <code>-u</code> option to only display non-duplicate lines:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-07-at-08.38.50.png" alt="Screen-Shot-2020-09-07-at-08.38.50" width="600" height="400" loading="lazy"></p>
<p>You can count the occurrences of each line with the <code>-c</code> option:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-07-at-08.37.15.png" alt="Screen-Shot-2020-09-07-at-08.37.15" width="600" height="400" loading="lazy"></p>
<p>Use the special combination:</p>
<pre><code class="lang-bash">sort dogs.txt | uniq -c | sort -nr
</code></pre>
<p>to then sort those lines by most frequent:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-07-at-08.37.49.png" alt="Screen-Shot-2020-09-07-at-08.37.49" width="600" height="400" loading="lazy"></p>
<h2 id="heading-the-linux-diff-command">The Linux <code>diff</code> command</h2>
<p><code>diff</code> is a handy command. Suppose you have 2 files, which contain almost the same information, but you can't find the difference between the two.</p>
<p><code>diff</code> will process the files and will tell you what's the difference.</p>
<p>Suppose you have 2 files: <code>dogs.txt</code> and <code>moredogs.txt</code>. The difference is that <code>moredogs.txt</code> contains one more dog name:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-07-at-08.55.18.png" alt="Screen-Shot-2020-09-07-at-08.55.18" width="600" height="400" loading="lazy"></p>
<p><code>diff dogs.txt moredogs.txt</code> will tell you the second file has one more line, line 3 with the line <code>Vanille</code>:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-07-at-08.56.05.png" alt="Screen-Shot-2020-09-07-at-08.56.05" width="600" height="400" loading="lazy"></p>
<p>If you invert the order of the files, it will tell you that the second file is missing line 3, whose content is <code>Vanille</code>:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-07-at-08.56.10.png" alt="Screen-Shot-2020-09-07-at-08.56.10" width="600" height="400" loading="lazy"></p>
<p>Using the <code>-y</code> option will compare the 2 files line by line:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-07-at-08.57.56.png" alt="Screen-Shot-2020-09-07-at-08.57.56" width="600" height="400" loading="lazy"></p>
<p>The <code>-u</code> option however will be more familiar to you, because that's the same used by the Git version control system to display differences between versions:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-07-at-08.58.23.png" alt="Screen-Shot-2020-09-07-at-08.58.23" width="600" height="400" loading="lazy"></p>
<p>Comparing directories works in the same way. You must use the <code>-r</code> option to compare recursively (going into subdirectories):</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-07-at-09.01.07.png" alt="Screen-Shot-2020-09-07-at-09.01.07" width="600" height="400" loading="lazy"></p>
<p>In case you're interested in which files differ, rather than the content, use the <code>r</code> and <code>q</code> options:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-07-at-09.01.30.png" alt="Screen-Shot-2020-09-07-at-09.01.30" width="600" height="400" loading="lazy"></p>
<p>There are many more options you can explore in the man page by running <code>man diff</code>:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-07-at-09.02.32.png" alt="Screen-Shot-2020-09-07-at-09.02.32" width="600" height="400" loading="lazy"></p>
<h2 id="heading-the-linux-echo-command">The Linux <code>echo</code> command</h2>
<p>The <code>echo</code> command does one simple job: it prints to the output the argument passed to it.</p>
<p>This example:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> <span class="hljs-string">"hello"</span>
</code></pre>
<p>will print <code>hello</code> to the terminal.</p>
<p>We can append the output to a file:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> <span class="hljs-string">"hello"</span> &gt;&gt; output.txt
</code></pre>
<p>We can interpolate environment variables:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> <span class="hljs-string">"The path variable is <span class="hljs-variable">$PATH</span>"</span>
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-15.44.33.png" alt="Screen-Shot-2020-09-03-at-15.44.33" width="600" height="400" loading="lazy"></p>
<p>Beware that special characters need to be escaped with a backslash <code>\</code>. <code>$</code> for example:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-15.51.18.png" alt="Screen-Shot-2020-09-03-at-15.51.18" width="600" height="400" loading="lazy">
This is just the start. We can do some nice things when it comes to interacting with the shell features.</p>
<p>We can echo the files in the current folder:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> *
</code></pre>
<p>We can echo the files in the current folder that start with the letter <code>o</code>:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> o*
</code></pre>
<p>Any valid Bash (or any shell you are using) command and feature can be used here.</p>
<p>You can print your home folder path:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> ~
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-15.46.36.png" alt="Screen-Shot-2020-09-03-at-15.46.36" width="600" height="400" loading="lazy"></p>
<p>You can also execute commands, and print the result to the standard output (or to file, as you saw):</p>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> $(ls -al)
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-15.48.55.png" alt="Screen-Shot-2020-09-03-at-15.48.55" width="600" height="400" loading="lazy"></p>
<p>Note that whitespace is not preserved by default. You need to wrap the command in double quotes to do so:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-15.49.53.png" alt="Screen-Shot-2020-09-03-at-15.49.53" width="600" height="400" loading="lazy"></p>
<p>You can generate a list of strings, for example ranges:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> {1..5}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-15.47.19.png" alt="Screen-Shot-2020-09-03-at-15.47.19" width="600" height="400" loading="lazy"></p>
<h2 id="heading-the-linux-chown-command">The Linux <code>chown</code> command</h2>
<p>Every file/directory in an Operating System like Linux or macOS (and every UNIX system in general) has an <strong>owner</strong>.</p>
<p>The owner of a file can do everything with it. It can decide the fate of that file.</p>
<p>The owner (and the <code>root</code> user) can change the owner to another user, too, using the <code>chown</code> command:</p>
<pre><code class="lang-bash">chown &lt;owner&gt; &lt;file&gt;
</code></pre>
<p>Like this:</p>
<pre><code class="lang-bash">chown flavio test.txt
</code></pre>
<p>For example if you have a file that's owned by <code>root</code>, you can't write to it as another user:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-18.40.49.png" alt="Screen-Shot-2020-09-03-at-18.40.49" width="600" height="400" loading="lazy"></p>
<p>You can use <code>chown</code> to transfer the ownership to you:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-18.40.58.png" alt="Screen-Shot-2020-09-03-at-18.40.58" width="600" height="400" loading="lazy">
It's rather common to need to change the ownership of a directory, and recursively all the files contained, plus all the subdirectories and the files contained in them, too.</p>
<p>You can do so using the <code>-R</code> flag:</p>
<pre><code class="lang-bash">chown -R &lt;owner&gt; &lt;file&gt;
</code></pre>
<p>Files/directories don't just have an owner, they also have a <strong>group</strong>. Through this command you can change that simultaneously while you change the owner:</p>
<pre><code class="lang-bash">chown &lt;owner&gt;:&lt;group&gt; &lt;file&gt;
</code></pre>
<p>Example:</p>
<pre><code class="lang-bash">chown flavio:users test.txt
</code></pre>
<p>You can also just change the group of a file using the <code>chgrp</code> command:</p>
<pre><code class="lang-bash">chgrp &lt;group&gt; &lt;filename&gt;
</code></pre>
<h2 id="heading-the-linux-chmod-command">The Linux <code>chmod</code> command</h2>
<p>Every file in the Linux / macOS Operating Systems (and UNIX systems in general) has 3 permissions: read, write, and execute.</p>
<p>Go into a folder, and run the <code>ls -al</code> command.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-18.49.22.png" alt="Screen-Shot-2020-09-03-at-18.49.22" width="600" height="400" loading="lazy">
The weird strings you see on each file line, like <code>drwxr-xr-x</code>, define the permissions of the file or folder.</p>
<p>Let's dissect it.</p>
<p>The first letter indicates the type of file:</p>
<ul>
<li><code>-</code> means it's a normal file</li>
<li><code>d</code> means it's a directory</li>
<li><code>l</code> means it's a link</li>
</ul>
<p>Then you have 3 sets of values:</p>
<ul>
<li>The first set represents the permissions of the <strong>owner</strong> of the file</li>
<li>The second set represents the permissions of the members of the <strong>group</strong> the file is associated to</li>
<li>The third set represents the permissions of the <strong>everyone else</strong></li>
</ul>
<p>Those sets are composed by 3 values. <code>rwx</code> means that specific <em>persona</em> has read, write and execution access. Anything that is removed is swapped with a <code>-</code>, which lets you form various combinations of values and relative permissions: <code>rw-</code>, <code>r--</code>, <code>r-x</code>, and so on.</p>
<p>You can change the permissions given to a file using the <code>chmod</code> command.</p>
<p><code>chmod</code> can be used in 2 ways. The first is using symbolic arguments, the second is using numeric arguments. Let's start with symbols first, which is more intuitive.</p>
<p>You type <code>chmod</code> followed by a space, and a letter:</p>
<ul>
<li><code>a</code> stands for <em>all</em></li>
<li><code>u</code> stands for <em>user</em></li>
<li><code>g</code> stands for <em>group</em></li>
<li><code>o</code> stands for <em>others</em></li>
</ul>
<p>Then you type either <code>+</code> or <code>-</code> to add a permission, or to remove it. Then you enter one or more permission symbols (<code>r</code>, <code>w</code>, <code>x</code>).</p>
<p>All followed by the file or folder name.</p>
<p>Here are some examples:</p>
<pre><code class="lang-bash">chmod a+r filename <span class="hljs-comment">#everyone can now read</span>
chmod a+rw filename <span class="hljs-comment">#everyone can now read and write</span>
chmod o-rwx filename <span class="hljs-comment">#others (not the owner, not in the same group of the file) cannot read, write or execute the file</span>
</code></pre>
<p>You can apply the same permissions to multiple personas by adding multiple letters before the <code>+</code>/<code>-</code>:</p>
<pre><code class="lang-bash">chmod og-r filename <span class="hljs-comment">#other and group can't read any more</span>
</code></pre>
<p>In case you are editing a folder, you can apply the permissions to every file contained in that folder using the <code>-r</code> (recursive) flag.</p>
<p>Numeric arguments are faster but I find them hard to remember when you are not using them day to day. You use a digit that represents the permissions of the persona. This number value can be a maximum of 7, and it's calculated in this way:</p>
<ul>
<li><code>1</code> if has execution permission</li>
<li><code>2</code> if has write permission</li>
<li><code>4</code> if has read permission</li>
</ul>
<p>This gives us 4 combinations:</p>
<ul>
<li><code>0</code> no permissions</li>
<li><code>1</code> can execute</li>
<li><code>2</code> can write</li>
<li><code>3</code> can write, execute</li>
<li><code>4</code> can read</li>
<li><code>5</code> can read, execute</li>
<li><code>6</code> can read, write</li>
<li><code>7</code> can read, write and execute</li>
</ul>
<p>We use them in pairs of 3, to set the permissions of all the 3 groups altogether:</p>
<pre><code class="lang-bash">chmod 777 filename
chmod 755 filename
chmod 644 filename
</code></pre>
<h2 id="heading-the-linux-umask-command">The Linux <code>umask</code> command</h2>
<p>When you create a file, you don't have to decide permissions up front. Permissions have defaults.</p>
<p>Those defaults can be controlled and modified using the <code>umask</code> command.</p>
<p>Typing <code>umask</code> with no arguments will show you the current umask, in this case <code>0022</code>:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-04-at-09.04.19.png" alt="Screen-Shot-2020-09-04-at-09.04.19" width="600" height="400" loading="lazy"></p>
<p>What does <code>0022</code> mean? That's an octal value that represents the permissions.</p>
<p>Another common value is <code>0002</code>.</p>
<p>Use <code>umask -S</code> to see a human-readable notation:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-04-at-09.08.18.png" alt="Screen-Shot-2020-09-04-at-09.08.18" width="600" height="400" loading="lazy">
In this case, the user (<code>u</code>), owner of the file, has read, write and execution permissions on files.</p>
<p>Other users belonging to the same group (<code>g</code>) have read and execution permission, same as all the other users (<code>o</code>).</p>
<p>In the numeric notation, we typically change the last 3 digits.</p>
<p>Here's a list that gives a meaning to the number:</p>
<ul>
<li><code>0</code> read, write, execute</li>
<li><code>1</code> read and write</li>
<li><code>2</code> read and execute</li>
<li><code>3</code> read only</li>
<li><code>4</code> write and execute</li>
<li><code>5</code> write only</li>
<li><code>6</code> execute only</li>
<li><code>7</code> no permissions</li>
</ul>
<p>Note that this numeric notation differs from the one we use in <code>chmod</code>.</p>
<p>We can set a new value for the mask setting the value in numeric format:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">umask</span> 002
</code></pre>
<p>or you can change a specific role's permission:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">umask</span> g+r
</code></pre>
<h2 id="heading-the-linux-du-command">The Linux <code>du</code> command</h2>
<p>The <code>du</code> command will calculate the size of a directory as a whole:</p>
<pre><code class="lang-bash">du
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-04-at-08.11.30.png" alt="Screen-Shot-2020-09-04-at-08.11.30" width="600" height="400" loading="lazy"></p>
<p>The <code>32</code> number here is a value expressed in bytes.</p>
<p>Running <code>du *</code> will calculate the size of each file individually:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-04-at-08.12.35.png" alt="Screen-Shot-2020-09-04-at-08.12.35" width="600" height="400" loading="lazy"></p>
<p>You can set <code>du</code> to display values in MegaBytes using <code>du -m</code>, and GigaBytes using <code>du -g</code>.</p>
<p>The <code>-h</code> option will show a human-readable notation for sizes, adapting to the size:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-04-at-08.14.40.png" alt="Screen-Shot-2020-09-04-at-08.14.40" width="600" height="400" loading="lazy"></p>
<p>Adding the <code>-a</code> option will print the size of each file in the directories, too:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-04-at-08.20.12.png" alt="Screen-Shot-2020-09-04-at-08.20.12" width="600" height="400" loading="lazy"></p>
<p>A handy thing is to sort the directories by size:</p>
<pre><code class="lang-bash">du -h &lt;directory&gt; | sort -nr
</code></pre>
<p>and then piping to <code>head</code> to only get the first 10 results:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-04-at-08.22.25.png" alt="Screen-Shot-2020-09-04-at-08.22.25" width="600" height="400" loading="lazy"></p>
<h2 id="heading-the-linux-df-command">The Linux <code>df</code> command</h2>
<p>The <code>df</code> command is used to get disk usage information.</p>
<p>Its basic form will print information about the volumes mounted:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-08-at-08.40.39.png" alt="Screen-Shot-2020-09-08-at-08.40.39" width="600" height="400" loading="lazy"></p>
<p>Using the <code>-h</code> option (<code>df -h</code>) will show those values in a human-readable format:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-08-at-08.40.50.png" alt="Screen-Shot-2020-09-08-at-08.40.50" width="600" height="400" loading="lazy"></p>
<p>You can also specify a file or directory name to get information about the specific volume it lives on:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-08-at-08.41.27.png" alt="Screen-Shot-2020-09-08-at-08.41.27" width="600" height="400" loading="lazy"></p>
<h2 id="heading-the-linux-basename-command">The Linux <code>basename</code> command</h2>
<p>Suppose you have a path to a file, for example <code>/Users/flavio/test.txt</code>.</p>
<p>Running</p>
<pre><code class="lang-bash">basename /Users/flavio/test.txt
</code></pre>
<p>will return the <code>test.txt</code> string:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-10-at-08.27.52.png" alt="Screen-Shot-2020-09-10-at-08.27.52" width="600" height="400" loading="lazy"></p>
<p>If you run <code>basename</code> on a path string that points to a directory, you will get the last segment of the path. In this example, <code>/Users/flavio</code> is a directory:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-10-at-08.28.11.png" alt="Screen-Shot-2020-09-10-at-08.28.11" width="600" height="400" loading="lazy"></p>
<h2 id="heading-the-linux-dirname-command">The Linux <code>dirname</code> command</h2>
<p>Suppose you have a path to a file, for example <code>/Users/flavio/test.txt</code>.</p>
<p>Running</p>
<pre><code class="lang-bash">dirname /Users/flavio/test.txt
</code></pre>
<p>will return the <code>/Users/flavio</code> string:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-10-at-08.31.08-1.png" alt="Screen-Shot-2020-09-10-at-08.31.08-1" width="600" height="400" loading="lazy"></p>
<h2 id="heading-the-linux-ps-command">The Linux <code>ps</code> command</h2>
<p>Your computer is running tons of different processes at all times.</p>
<p>You can inspect them all using the <code>ps</code> command:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-02-at-12.25.08.png" alt="Screen-Shot-2020-09-02-at-12.25.08" width="600" height="400" loading="lazy"></p>
<p>This is the list of user-initiated processes currently running in the current session.</p>
<p>Here I have a few <code>fish</code> shell instances, mostly opened by VS Code inside the editor, and an instance of Hugo running the development preview of a site.</p>
<p>Those are just the commands assigned to the current user. To list <strong>all</strong> processes we need to pass some options to <code>ps</code>.</p>
<p>The most common one I use is <code>ps ax</code>:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-02-at-12.26.00.png" alt="Screen-Shot-2020-09-02-at-12.26.00" width="600" height="400" loading="lazy"></p>
<blockquote>
<p>The <code>a</code> option is used to also list other users' processes, not just your own. <code>x</code> shows processes not linked to any terminal (not initiated by users through a terminal).</p>
</blockquote>
<p>As you can see, the longer commands are cut. Use the command <code>ps axww</code> to continue the command listing on a new line instead of cutting it:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-02-at-12.30.22.png" alt="Screen-Shot-2020-09-02-at-12.30.22" width="600" height="400" loading="lazy"></p>
<blockquote>
<p>We need to specify <code>w</code> 2 times to apply this setting (it's not a typo).</p>
</blockquote>
<p>You can search for a specific process combining <code>grep</code> with a pipe, like this:</p>
<pre><code class="lang-bash">ps axww | grep <span class="hljs-string">"Visual Studio Code"</span>
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-02-at-12.33.45.png" alt="Screen-Shot-2020-09-02-at-12.33.45" width="600" height="400" loading="lazy">
The columns returned by <code>ps</code> represent some key information.</p>
<p>The first information is <code>PID</code>, the process ID. This is key when you want to reference this process in another command, for example to kill it.</p>
<p>Then we have <code>TT</code> that tells us the terminal id used.</p>
<p>Then <code>STAT</code> tells us the state of the process:</p>
<p><code>I</code> a process that is idle (sleeping for longer than about 20 seconds)
<code>R</code> a runnable process
<code>S</code> a process that is sleeping for less than about 20 seconds
<code>T</code> a stopped process
<code>U</code> a process in uninterruptible wait
<code>Z</code> a dead process (a <em>zombie</em>)</p>
<p>If you have more than one letter, the second represents further information, which can be very technical.</p>
<p>It's common to have <code>+</code> which indicates that the process is in the foreground in its terminal. <code>s</code> means the process is a <a target="_blank" href="https://unix.stackexchange.com/questions/18166/what-are-session-leaders-in-ps">session leader</a>.</p>
<p><code>TIME</code> tells us how long the process has been running.</p>
<h2 id="heading-the-linux-top-command">The Linux <code>top</code> command</h2>
<p>The <code>top</code> command is used to display dynamic real-time information about running processes in the system.</p>
<p>It's really handy to understand what is going on.</p>
<p>Its usage is simple – you just type <code>top</code>, and the terminal will be fully immersed in this new view:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-11.39.53.png" alt="Screen-Shot-2020-09-03-at-11.39.53" width="600" height="400" loading="lazy">
The process is long-running. To quit, you can type the <code>q</code> letter or <code>ctrl-C</code>.</p>
<p>There's a lot of information being given to us: the number of processes, how many are running or sleeping, the system load, the CPU usage, and a lot more.</p>
<p>Below, the list of processes taking the most memory and CPU is constantly updated.</p>
<p>By default, as you can see from the <code>%CPU</code> column highlighted, they are sorted by the CPU used.</p>
<p>You can add a flag to sort processes by memory utilized:</p>
<pre><code class="lang-bash">top -o mem
</code></pre>
<h2 id="heading-the-linux-kill-command">The Linux <code>kill</code> command</h2>
<p>Linux processes can receive <strong>signals</strong> and react to them.</p>
<p>That's one way we can interact with running programs.</p>
<p>The <code>kill</code> program can send a variety of signals to a program.</p>
<p>It's not just used to terminate a program, like the name would suggest, but that's its main job.</p>
<p>We use it in this way:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">kill</span> &lt;PID&gt;
</code></pre>
<p>By default, this sends the <code>TERM</code> signal to the process id specified.</p>
<p>We can use flags to send other signals, including:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">kill</span> -HUP &lt;PID&gt;
<span class="hljs-built_in">kill</span> -INT &lt;PID&gt;
<span class="hljs-built_in">kill</span> -KILL &lt;PID&gt;
<span class="hljs-built_in">kill</span> -TERM &lt;PID&gt;
<span class="hljs-built_in">kill</span> -CONT &lt;PID&gt;
<span class="hljs-built_in">kill</span> -STOP &lt;PID&gt;
</code></pre>
<p><code>HUP</code> means <strong>hang up</strong>. It's sent automatically when a terminal window that started a process is closed before terminating the process.</p>
<p><code>INT</code> means <strong>interrupt</strong>, and it sends the same signal used when we press <code>ctrl-C</code> in the terminal, which usually terminates the process.</p>
<p><code>KILL</code> is not sent to the process, but to the operating system kernel, which immediately stops and terminates the process.</p>
<p><code>TERM</code> means <strong>terminate</strong>. The process will receive it and terminate itself. It's the default signal sent by <code>kill</code>.</p>
<p><code>CONT</code> means <strong>continue</strong>. It can be used to resume a stopped process.</p>
<p><code>STOP</code> is not sent to the process, but to the operating system kernel, which immediately stops (but does not terminate) the process.</p>
<p>You might see numbers used instead, like <code>kill -1 &lt;PID&gt;</code>. In this case,</p>
<p><code>1</code> corresponds to <code>HUP</code>.
<code>2</code> corresponds to <code>INT</code>.
<code>9</code> corresponds to <code>KILL</code>.
<code>15</code> corresponds to <code>TERM</code>.
<code>18</code> corresponds to <code>CONT</code>.
<code>15</code> corresponds to <code>STOP</code>.</p>
<h2 id="heading-the-linux-killall-command">The Linux <code>killall</code> command</h2>
<p>Similar to the <code>kill</code> command, <code>killall</code> will send the signal to multiple processes at once instead of sending a signal to a specific process id.</p>
<p>This is the syntax:</p>
<pre><code class="lang-bash">killall &lt;name&gt;
</code></pre>
<p>where <code>name</code> is the name of a program. For example you can have multiple instances of the <code>top</code> program running, and <code>killall top</code> will terminate them all.</p>
<p>You can specify the signal, like with <code>kill</code> (and check the <code>kill</code> tutorial to read more about the specific kinds of signals we can send), for example:</p>
<pre><code class="lang-bash">killall -HUP top
</code></pre>
<h2 id="heading-the-linux-jobs-command">The Linux <code>jobs</code> command</h2>
<p>When we run a command in Linux / macOS, we can set it to run in the background using the <code>&amp;</code> symbol after the command.</p>
<p>For example we can run <code>top</code> in the background:</p>
<pre><code class="lang-bash">top &amp;
</code></pre>
<p>This is very handy for long-running programs.</p>
<p>We can get back to that program using the <code>fg</code> command. This works fine if we just have one job in the background, otherwise we need to use the job number: <code>fg 1</code>, <code>fg 2</code> and so on.</p>
<p>To get the job number, we use the <code>jobs</code> command.</p>
<p>Say we run <code>top &amp;</code> and then <code>top -o mem &amp;</code>, so we have 2 top instances running. <code>jobs</code> will tell us this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-11.49.42.png" alt="Screen-Shot-2020-09-03-at-11.49.42" width="600" height="400" loading="lazy">
Now we can switch back to one of those using <code>fg &lt;jobid&gt;</code>. To stop the program again we can hit <code>cmd-Z</code>.</p>
<p>Running <code>jobs -l</code> will also print the process id of each job.</p>
<h2 id="heading-the-linux-bg-command">The Linux <code>bg</code> command</h2>
<p>When a command is running you can suspend it using <code>ctrl-Z</code>.</p>
<p>The command will immediately stop, and you get back to the shell terminal.</p>
<p>You can resume the execution of the command in the background, so it will keep running but it will not prevent you from doing other work in the terminal.</p>
<p>In this example I have 2 commands stopped:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-16.06.18.png" alt="Screen-Shot-2020-09-03-at-16.06.18" width="600" height="400" loading="lazy">
I can run <code>bg 1</code> to resume in the background the execution of the job #1.</p>
<p>I could have also said <code>bg</code> without any option, as the default is to pick the job #1 in the list.</p>
<h2 id="heading-the-linux-fg-command">The Linux <code>fg</code> command</h2>
<p>When a command is running in the background, because you started it with <code>&amp;</code> at the end (example: <code>top &amp;</code> or because you put it in the background with the <code>bg</code> command), you can put it to the foreground using <code>fg</code>.</p>
<p>Running</p>
<pre><code class="lang-bash"><span class="hljs-built_in">fg</span>
</code></pre>
<p>will resume in the foreground the last job that was suspended.</p>
<p>You can also specify which job you want to resume to the foreground passing the job number, which you can get using the <code>jobs</code> command.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-16.12.46.png" alt="Screen-Shot-2020-09-03-at-16.12.46" width="600" height="400" loading="lazy"></p>
<p>Running <code>fg 2</code> will resume job #2:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-16.12.54.png" alt="Screen-Shot-2020-09-03-at-16.12.54" width="600" height="400" loading="lazy"></p>
<h2 id="heading-the-linux-type-command">The Linux <code>type</code> command</h2>
<p>A command can be one of those 4 types:</p>
<ul>
<li>an executable</li>
<li>a shell built-in program</li>
<li>a shell function</li>
<li>an alias</li>
</ul>
<p>The <code>type</code> command can help figure this out, in case we want to know or we're just curious. It will tell you how the command will be interpreted.</p>
<p>The output will depend on the shell used. This is Bash:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-16.32.50.png" alt="Screen-Shot-2020-09-03-at-16.32.50" width="600" height="400" loading="lazy"></p>
<p>This is Zsh:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-16.32.57.png" alt="Screen-Shot-2020-09-03-at-16.32.57" width="600" height="400" loading="lazy"></p>
<p>This is Fish:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-16.33.06.png" alt="Screen-Shot-2020-09-03-at-16.33.06" width="600" height="400" loading="lazy">
One of the most interesting things here is that for aliases it will tell you what it is aliasing to. You can see the <code>ll</code> alias, in the case of Bash and Zsh, but Fish provides it by default, so it will tell you it's a built-in shell function.</p>
<h2 id="heading-the-linux-which-command">The Linux <code>which</code> command</h2>
<p>Suppose you have a command you can execute, because it's in the shell path, but you want to know where it is located.</p>
<p>You can do so using <code>which</code>. The command will return the path to the command specified:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-17.22.47.png" alt="Screen-Shot-2020-09-03-at-17.22.47" width="600" height="400" loading="lazy">
<code>which</code> will only work for executables stored on disk, not aliases or built-in shell functions.</p>
<h2 id="heading-the-linux-nohup-command">The Linux <code>nohup</code> command</h2>
<p>Sometimes you have to run a long-lived process on a remote machine, and then you need to disconnect.</p>
<p>Or you simply want to prevent the command from being halted if there's any network issue between you and the server.</p>
<p>The way to make a command run even after you log out or close the session to a server is to use the <code>nohup</code> command.</p>
<p>Use <code>nohup &lt;command&gt;</code> to let the process continue working even after you log out.</p>
<h2 id="heading-the-linux-xargs-command">The Linux <code>xargs</code> command</h2>
<p>The <code>xargs</code> command is used in a UNIX shell to convert input from standard input into arguments to a command.</p>
<p>In other words, through the use of <code>xargs</code> the output of a command is used as the input of another command.</p>
<p>Here's the syntax you will use:</p>
<pre><code class="lang-bash">command1 | xargs command2
</code></pre>
<p>We use a pipe (<code>|</code>) to pass the output to <code>xargs</code>. That will take care of running the <code>command2</code> command, using the output of <code>command1</code> as its argument(s).</p>
<p>Let's do a simple example. You want to remove some specific files from a directory. Those files are listed inside a text file.</p>
<p>We have 3 files: <code>file1</code>, <code>file2</code>, <code>file3</code>.</p>
<p>In <code>todelete.txt</code> we have a list of files we want to delete, in this example <code>file1</code> and <code>file3</code>:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-08-at-07.45.28.png" alt="Screen-Shot-2020-09-08-at-07.45.28" width="600" height="400" loading="lazy"></p>
<p>We will channel the output of <code>cat todelete.txt</code> to the <code>rm</code> command, through <code>xargs</code>.</p>
<p>In this way:</p>
<pre><code class="lang-bash">cat todelete.txt | xargs rm
</code></pre>
<p>That's the result, the files we listed are now deleted:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-08-at-07.46.39.png" alt="Screen-Shot-2020-09-08-at-07.46.39" width="600" height="400" loading="lazy"></p>
<p>The way it works is that <code>xargs</code> will run <code>rm</code> 2 times, one for each line returned by <code>cat</code>.</p>
<p>This is the simplest usage of <code>xargs</code>. There are several options we can use.</p>
<p>One of the most useful, in my opinion (especially when starting to learn <code>xargs</code>), is <code>-p</code>. Using this option will make <code>xargs</code> print a confirmation prompt with the action it's going to take:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-08-at-08.19.09.png" alt="Screen-Shot-2020-09-08-at-08.19.09" width="600" height="400" loading="lazy"></p>
<p>The <code>-n</code> option lets you tell <code>xargs</code> to perform one iteration at a time, so you can individually confirm them with <code>-p</code>. Here we tell <code>xargs</code> to perform one iteration at a time with <code>-n1</code>:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-08-at-08.32.58.png" alt="Screen-Shot-2020-09-08-at-08.32.58" width="600" height="400" loading="lazy"></p>
<p>The <code>-I</code> option is another widely used one. It allows you to get the output into a placeholder, and then you can do various things.</p>
<p>One of them is to run multiple commands:</p>
<pre><code class="lang-bash">command1 | xargs -I % /bin/bash -c <span class="hljs-string">'command2 %; command3 %'</span>
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-08-at-08.35.37.png" alt="Screen-Shot-2020-09-08-at-08.35.37" width="600" height="400" loading="lazy"></p>
<blockquote>
<p>You can swap the <code>%</code> symbol I used above with anything else – it's a variable.</p>
</blockquote>
<h2 id="heading-the-linux-vim-editor-command">The Linux <code>vim</code> editor command</h2>
<p><code>vim</code> is a <strong>very</strong> popular file editor, especially among programmers. It's actively developed and frequently updated, and there's a big community around it. There's even a <a target="_blank" href="https://vimconf.org/">Vim conference</a>!</p>
<p><code>vi</code> in modern systems is just an alias for <code>vim</code>, which means <code>vi</code> i<code>m</code>proved.</p>
<p>You start it by running <code>vi</code> on the command line.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screenshot-2019-02-10-at-11.44.36.png" alt="Screenshot-2019-02-10-at-11.44.36" width="600" height="400" loading="lazy"></p>
<p>You can specify a filename at invocation time to edit that specific file:</p>
<pre><code class="lang-bash">vi test.txt
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screenshot-2019-02-10-at-11.36.21.png" alt="Screenshot-2019-02-10-at-11.36.21" width="600" height="400" loading="lazy"></p>
<p>You have to know that Vim has 2 main modes:</p>
<ul>
<li><em>command</em> (or <em>normal</em>) mode</li>
<li><em>insert</em> mode</li>
</ul>
<p>When you start the editor, you are in command mode. You can't enter text like you expect from a GUI-based editor. You have to enter <strong>insert mode</strong>. </p>
<p>You can do this by pressing the <code>i</code> key. Once you do so, the <code>-- INSERT --</code> word appears at the bottom of the editor:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screenshot-2019-02-10-at-11.47.39.png" alt="Screenshot-2019-02-10-at-11.47.39" width="600" height="400" loading="lazy"></p>
<p>Now you can start typing and filling the screen with the file contents:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screenshot-2019-02-10-at-11.48.39.png" alt="Screenshot-2019-02-10-at-11.48.39" width="600" height="400" loading="lazy"></p>
<p>You can move around the file with the arrow keys, or using the <code>h</code> - <code>j</code> - <code>k</code> - <code>l</code> keys. <code>h-l</code> for left-right, <code>j-k</code> for down-up.</p>
<p>Once you are done editing you can press the <code>esc</code> key to exit insert mode and go back to <strong>command mode</strong>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screenshot-2019-02-10-at-11.48.44.png" alt="Screenshot-2019-02-10-at-11.48.44" width="600" height="400" loading="lazy">
At this point you can navigate the file, but you can't add content to it (and be careful which keys you press, as they might be commands).</p>
<p>One thing you might want to do now is <strong>save the file</strong>. You can do so by pressing <code>:</code> (colon), then <code>w</code>.</p>
<p>You can <strong>save and quit</strong> by pressing <code>:</code> then <code>w</code> and <code>q</code>: <code>:wq</code></p>
<p>You can <strong>quit without saving</strong> by pressing <code>:</code> then <code>q</code> and <code>!</code>: <code>:q!</code></p>
<p>You can <strong>undo</strong> and edit by going to command mode and pressing <code>u</code>. You can <strong>redo</strong> (cancel an undo) by pressing <code>ctrl-r</code>.</p>
<p>Those are the basics of working with Vim. From here starts a rabbit hole we can't go into in this little introduction.</p>
<p>I will only mention those commands that will get you started editing with Vim:</p>
<ul>
<li>pressing the <code>x</code> key deletes the character currently highlighted</li>
<li>pressing <code>A</code> goes to the end of the currently selected line</li>
<li>press <code>0</code> to go to the start of the line</li>
<li>go to the first character of a word and press <code>d</code> followed by <code>w</code> to delete that word. If you follow it with <code>e</code> instead of <code>w</code>, the white space before the next word is preserved</li>
<li>use a number between <code>d</code> and <code>w</code> to delete more than 1 word, for example use <code>d3w</code> to delete 3 words forward</li>
<li>press <code>d</code> followed by <code>d</code> to delete a whole entire line. Press <code>d</code> followed by <code>$</code> to delete the entire line from where the cursor is, until the end</li>
</ul>
<p>To find out more about Vim I can recommend the <a target="_blank" href="https://vimhelp.org/vim_faq.txt.html">Vim FAQ</a>. You can also run the <code>vimtutor</code> command, which should already be installed in your system and will greatly help you start your <code>vim</code> exploration.</p>
<h2 id="heading-the-linux-emacs-editor-command">The Linux <code>emacs</code> editor command</h2>
<p><code>emacs</code> is an awesome editor and it's historically regarded as <em>the</em> editor for UNIX systems. Famously, <code>vi</code> vs <code>emacs</code> flame wars and heated discussions have caused many unproductive hours for developers around the world.</p>
<p><code>emacs</code> is very powerful. Some people use it all day long as a kind of operating system (https://news.ycombinator.com/item?id=19127258). We'll just talk about the basics here.</p>
<p>You can open a new emacs session simply by invoking <code>emacs</code>:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screenshot-2019-02-10-at-12.14.18.png" alt="Screenshot-2019-02-10-at-12.14.18" width="600" height="400" loading="lazy"></p>
<blockquote>
<p>macOS users, stop a second now. If you are on Linux there are no problems, but macOS does not ship applications using GPLv3, and every built-in UNIX command that has been updated to GPLv3 has not been updated. </p>
<p>While there is a little problem with the commands I listed up to now, in this case using an emacs version from 2007 is not exactly the same as using a version with 12 years of improvements and change. </p>
<p>This is not a problem with Vim, which is up to date. To fix this, run <code>brew install emacs</code> and running <code>emacs</code> will use the new version from Homebrew (make sure you have <a target="_blank" href="https://flaviocopes.com/homebrew/">Homebrew</a> installed).</p>
</blockquote>
<p>You can also edit an existing file by calling <code>emacs &lt;filename&gt;</code>:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screenshot-2019-02-10-at-13.12.49.png" alt="Screenshot-2019-02-10-at-13.12.49" width="600" height="400" loading="lazy"></p>
<p>You can now start editing. Once you are done, press <code>ctrl-x</code> followed by <code>ctrl-w</code>. You confirm the folder:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screenshot-2019-02-10-at-13.14.29.png" alt="Screenshot-2019-02-10-at-13.14.29" width="600" height="400" loading="lazy"></p>
<p>and Emacs tells you the file exists, asking you if it should overwrite it:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screenshot-2019-02-10-at-13.14.32.png" alt="Screenshot-2019-02-10-at-13.14.32" width="600" height="400" loading="lazy"></p>
<p>Answer <code>y</code>, and you get a confirmation of success:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screenshot-2019-02-10-at-13.14.35.png" alt="Screenshot-2019-02-10-at-13.14.35" width="600" height="400" loading="lazy">
You can exit Emacs by pressing <code>ctrl-x</code> followed by <code>ctrl-c</code>.
Or <code>ctrl-x</code> followed by <code>c</code> (keep <code>ctrl</code> pressed).</p>
<p>There is a lot to know about Emacs, certainly more than I am able to write in this little introduction. I encourage you to open Emacs and press <code>ctrl-h</code> <code>r</code> to open the built-in manual and <code>ctrl-h</code> <code>t</code> to open the official tutorial.</p>
<h2 id="heading-the-linux-nano-editor-command">The Linux <code>nano</code> editor command</h2>
<p><code>nano</code> is a beginner friendly editor.</p>
<p>Run it using <code>nano &lt;filename&gt;</code>.</p>
<p>You can directly type characters into the file without worrying about modes.</p>
<p>You can quit without editing using <code>ctrl-X</code>. If you edited the file buffer, the editor will ask you for confirmation and you can save the edits, or discard them. </p>
<p>The help at the bottom shows you the keyboard commands that let you work with the file:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screenshot-2019-02-10-at-11.03.51.png" alt="Screenshot-2019-02-10-at-11.03.51" width="600" height="400" loading="lazy">
<code>pico</code> is more or less the same, although <code>nano</code> is the GNU version of <code>pico</code> which at some point in history was not open source. The <code>nano</code> clone was made to satisfy the GNU operating system license requirements.</p>
<h2 id="heading-the-linux-whoami-command">The Linux <code>whoami</code> command</h2>
<p>Type <code>whoami</code> to print the user name currently logged in to the terminal session:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-18.08.05.png" alt="Screen-Shot-2020-09-03-at-18.08.05" width="600" height="400" loading="lazy"></p>
<blockquote>
<p>Note: this is different from the <code>who am i</code> command, which prints more information</p>
</blockquote>
<h2 id="heading-the-linux-who-command">The Linux <code>who</code> command</h2>
<p>The <code>who</code> command displays the users logged in to the system.</p>
<p>Unless you're using a server multiple people have access to, chances are you will be the only user logged in, multiple times:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-18.03.05.png" alt="Screen-Shot-2020-09-03-at-18.03.05" width="600" height="400" loading="lazy"></p>
<p>Why multiple times? Because each shell opened will count as an access.</p>
<p>You can see the name of the terminal used, and the time/day the session was started.</p>
<p>The <code>-aH</code> flags will tell <code>who</code> to display more information, including the idle time and the process ID of the terminal:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-18.05.29.png" alt="Screen-Shot-2020-09-03-at-18.05.29" width="600" height="400" loading="lazy"></p>
<p>The special <code>who am i</code> command will list the current terminal session details:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-18.06.35.png" alt="Screen-Shot-2020-09-03-at-18.06.35" width="600" height="400" loading="lazy"></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-18.07.30.png" alt="Screen-Shot-2020-09-03-at-18.07.30" width="600" height="400" loading="lazy"></p>
<h2 id="heading-the-linux-su-command">The Linux <code>su</code> command</h2>
<p>While you're logged in to the terminal shell with one user, you might need to switch to another user.</p>
<p>For example you're logged in as root to perform some maintenance, but then you want to switch to a user account.</p>
<p>You can do so with the <code>su</code> command:</p>
<pre><code class="lang-bash">su &lt;username&gt;
</code></pre>
<p>For example: <code>su flavio</code>.</p>
<p>If you're logged in as a user, running <code>su</code> without anything else will prompt you to enter the <code>root</code> user password, as that's the default behavior.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-18.18.09.png" alt="Screen-Shot-2020-09-03-at-18.18.09" width="600" height="400" loading="lazy">
<code>su</code> will start a new shell as another user.</p>
<p>When you're done, typing <code>exit</code> in the shell will close that shell, and will return you back to the current user's shell.</p>
<h2 id="heading-the-linux-sudo-command">The Linux <code>sudo</code> command</h2>
<p><code>sudo</code> is commonly used to run a command as root.</p>
<p>You must be enabled to use <code>sudo</code>, and once you are, you can run commands as root by entering your user's password (<em>not</em> the root user password).</p>
<p>The permissions are highly configurable, which is great especially in a multi-user server environment. Some users can be granted access to running specific commands through <code>sudo</code>.</p>
<p>For example you can edit a system configuration file:</p>
<pre><code class="lang-bash">sudo nano /etc/hosts
</code></pre>
<p>which would otherwise fail to save since you don't have the permissions
for it.</p>
<p>You can run <code>sudo -i</code> to start a shell as root:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-18.25.50.png" alt="Screen-Shot-2020-09-03-at-18.25.50" width="600" height="400" loading="lazy"></p>
<p>You can use <code>sudo</code> to run commands as any user. <code>root</code> is the default, but use the <code>-u</code> option to specify another user:</p>
<pre><code class="lang-bash">sudo -u flavio ls /Users/flavio
</code></pre>
<h2 id="heading-the-linux-passwd-command">The Linux <code>passwd</code> command</h2>
<p>Users in Linux have a password assigned. You can change the password using the <code>passwd</code> command.</p>
<p>There are two situations here.</p>
<p>The first is when you want to change your password. In this case you type:</p>
<pre><code class="lang-bash">passwd
</code></pre>
<p>and an interactive prompt will ask you for the old password, then it will ask you for the new one:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-04-at-07.32.05.png" alt="Screen-Shot-2020-09-04-at-07.32.05" width="600" height="400" loading="lazy"></p>
<p>When you're <code>root</code> (or have superuser privileges) you can set the username for which you want to change the password:</p>
<pre><code class="lang-bash">passwd &lt;username&gt; &lt;new password&gt;
</code></pre>
<p>In this case you don't need to enter the old one.</p>
<h2 id="heading-the-linux-ping-command">The Linux <code>ping</code> command</h2>
<p>The <code>ping</code> command pings a specific network host, on the local network or on the Internet.</p>
<p>You use it with the syntax <code>ping &lt;host&gt;</code> where <code>&lt;host&gt;</code> could be a domain name, or an IP address.</p>
<p>Here's an example pinging <code>google.com</code>:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-09-at-15.21.46.png" alt="Screen-Shot-2020-09-09-at-15.21.46" width="600" height="400" loading="lazy">
The command sends a request to the server, and the server returns a response.</p>
<p><code>ping</code> keeps sending the request every second, by default. It will keep running until you stop it with <code>ctrl-C</code>, unless you pass the number of times you want to try with the <code>-c</code> option: <code>ping -c 2 google.com</code>.</p>
<p>Once <code>ping</code> is stopped, it will print some statistics about the results: the percentage of packages lost, and statistics about the network performance.</p>
<p>As you can see the screen prints the host IP address, and the time that it took to get the response back.</p>
<p>Not all servers support pinging, in case the request times out:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-09-at-15.21.27.png" alt="Screen-Shot-2020-09-09-at-15.21.27" width="600" height="400" loading="lazy"></p>
<p>Sometimes this is done on purpose, to "hide" the server, or just to reduce the load. The ping packets can also be filtered by firewalls.</p>
<p><code>ping</code> works using the <strong>ICMP protocol</strong> (<em>Internet Control Message Protocol</em>), a network layer protocol just like TCP or UDP.</p>
<p>The request sends a packet to the server with the <code>ECHO_REQUEST</code> message, and the server returns a <code>ECHO_REPLY</code> message. I won't go into details, but this is the basic concept.</p>
<p>Pinging a host is useful to know if the host is reachable (supposing it implements ping), and how distant it is in terms of how long it takes to get back to you. </p>
<p>Usually the nearer the server is geographically, the less time it will take to return back to you. Simple physical laws cause a longer distance to introduce more delay in the cables.</p>
<h2 id="heading-the-linux-traceroute-command">The Linux <code>traceroute</code> command</h2>
<p>When you try to reach a host on the Internet, you go through your home router. Then you reach your ISP network, which in turn goes through its own upstream network router, and so on, until you finally reach the host.</p>
<p>Have you ever wanted to know what steps your packets go through to do that?</p>
<p>The <code>traceroute</code> command is made for this.</p>
<p>You invoke</p>
<pre><code class="lang-bash">traceroute &lt;host&gt;
</code></pre>
<p>and it will (slowly) gather all the information while the packet travels.</p>
<p>In this example I tried reaching for my blog with <code>traceroute flaviocopes.com</code>:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-09-at-16.32.01.png" alt="Screen-Shot-2020-09-09-at-16.32.01" width="600" height="400" loading="lazy"></p>
<p>Not every router travelled returns us information. In this case, <code>traceroute</code> prints <code>* * *</code>. Otherwise, we can see the hostname, the IP address, and some performance indicator.</p>
<p>For every router we can see 3 samples, which means traceroute tries by default 3 times to get you a good indication of the time needed to reach it. </p>
<p>This is why it takes this long to execute <code>traceroute</code> compared to simply doing a <code>ping</code> to that host.</p>
<p>You can customize this number with the <code>-q</code> option:</p>
<pre><code class="lang-bash">traceroute -q 1 flaviocopes.com
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-09-at-16.36.07.png" alt="Screen-Shot-2020-09-09-at-16.36.07" width="600" height="400" loading="lazy"></p>
<h2 id="heading-the-linux-clear-command">The Linux <code>clear</code> command</h2>
<p>Type <code>clear</code> to clear all the previous commands that were run in the current terminal.</p>
<p>The screen will clear and you will just see the prompt at the top:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-18.10.32.png" alt="Screen-Shot-2020-09-03-at-18.10.32" width="600" height="400" loading="lazy"></p>
<blockquote>
<p>Note: this command has a handy shortcut: <code>ctrl-L</code></p>
</blockquote>
<p>Once you do that, you will lose access to scrolling to see the output of the previous commands entered.</p>
<p>So you might want to use <code>clear -x</code> instead, which still clears the screen, but lets you go back to see the previous work by scrolling up.</p>
<h2 id="heading-the-linux-history-command">The Linux <code>history</code> command</h2>
<p>Every time you run a command, it's memorized in the history.</p>
<p>You can display all the history using:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">history</span>
</code></pre>
<p>This shows the history with numbers:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-04-at-08.03.10.png" alt="Screen-Shot-2020-09-04-at-08.03.10" width="600" height="400" loading="lazy"></p>
<p>You can use the syntax <code>!&lt;command number&gt;</code> to repeat a command stored in the history. In the above example typing <code>!121</code> will repeat the <code>ls -al | wc -l</code> command.</p>
<p>Typically the last 500 commands are stored in the history.</p>
<p>You can combine this with <code>grep</code> to find a command you ran:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">history</span> | grep docker
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-04-at-08.04.50.png" alt="Screen-Shot-2020-09-04-at-08.04.50" width="600" height="400" loading="lazy">
To clear the history, run <code>history -c</code>.</p>
<h2 id="heading-the-linux-export-command">The Linux <code>export</code> command</h2>
<p>The <code>export</code> command is used to export variables to child processes.</p>
<p>What does this mean?</p>
<p>Suppose you have a variable TEST defined in this way:</p>
<pre><code class="lang-bash">TEST=<span class="hljs-string">"test"</span>
</code></pre>
<p>You can print its value using <code>echo $TEST</code>:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-09-at-17.32.49.png" alt="Screen-Shot-2020-09-09-at-17.32.49" width="600" height="400" loading="lazy"></p>
<p>But if you try defining a Bash script in a file <code>script.sh</code> with the above command:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-09-at-17.35.23.png" alt="Screen-Shot-2020-09-09-at-17.35.23" width="600" height="400" loading="lazy"></p>
<p>Then when you set <code>chmod u+x script.sh</code> and you execute this script with <code>./script.sh</code>, the <code>echo $TEST</code> line will print nothing!</p>
<p>This is because in Bash the <code>TEST</code> variable was defined local to the shell. When executing a shell script or another command, a subshell is launched to execute it, which does not contain the current shell local variables.</p>
<p>To make the variable available there we need to define <code>TEST</code> not in this way:</p>
<pre><code class="lang-bash">TEST=<span class="hljs-string">"test"</span>
</code></pre>
<p>but in this way:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">export</span> TEST=<span class="hljs-string">"test"</span>
</code></pre>
<p>Try that, and running <code>./script.sh</code> now should print "test":</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-09-at-17.37.56.png" alt="Screen-Shot-2020-09-09-at-17.37.56" width="600" height="400" loading="lazy">
Sometimes you need to append something to a variable. It's often done with the <code>PATH</code> variable. You use this syntax:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">export</span> PATH=<span class="hljs-variable">$PATH</span>:/new/path
</code></pre>
<p>It's common to use <code>export</code> when you create new variables in this way. But you can also use it when you create variables in the <code>.bash_profile</code> or <code>.bashrc</code> configuration files with Bash, or in <code>.zshenv</code> with Zsh.</p>
<p>To remove a variable, use the <code>-n</code> option:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">export</span> -n TEST
</code></pre>
<p>Calling <code>export</code> without any option will list all the exported variables.</p>
<h2 id="heading-the-linux-crontab-command">The Linux <code>crontab</code> command</h2>
<p>Cron jobs are jobs that are scheduled to run at specific intervals. You might have a command perform something every hour, or every day, or every 2 weeks. Or on weekends. </p>
<p>They are very powerful, especially when used on servers to perform maintenance and automations.</p>
<p>The <code>crontab</code> command is the entry point to work with cron jobs.</p>
<p>The first thing you can do is to explore which cron jobs are defined by you:</p>
<pre><code class="lang-bash">crontab -l
</code></pre>
<p>You might have none, like me:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-09-at-17.54.31.png" alt="Screen-Shot-2020-09-09-at-17.54.31" width="600" height="400" loading="lazy"></p>
<p>Run</p>
<pre><code class="lang-bash">crontab -e
</code></pre>
<p>to edit the cron jobs, and add new ones.</p>
<p>By default this opens with the default editor, which is usually <code>vim</code>. I like <code>nano</code> more. You can use this line to use a different editor:</p>
<pre><code class="lang-bash">EDITOR=nano crontab -e
</code></pre>
<p>Now you can add one line for each cron job.</p>
<p>The syntax to define cron jobs is kind of scary. This is why I usually use a website to help me generate it without errors: <a target="_blank" href="https://crontab-generator.org/">https://crontab-generator.org/</a></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-09-at-18.03.57.png" alt="Screen-Shot-2020-09-09-at-18.03.57" width="600" height="400" loading="lazy"></p>
<p>You pick a time interval for the cron job, and you type the command to execute.</p>
<p>I chose to run a script located in <code>/Users/flavio/test.sh</code> every 12 hours. This is the crontab line I need to run:</p>
<pre><code class="lang-txt">* */12 * * * /Users/flavio/test.sh &gt;/dev/null 2&gt;&amp;1
</code></pre>
<p>I run <code>crontab -e</code>:</p>
<pre><code class="lang-bash">EDITOR=nano crontab -e
</code></pre>
<p>and I add that line, then I press <code>ctrl-X</code> and press <code>y</code> to save.</p>
<p>If all goes well, the cron job is set up:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-09-at-18.06.19.png" alt="Screen-Shot-2020-09-09-at-18.06.19" width="600" height="400" loading="lazy"></p>
<p>Once this is done, you can see the list of active cron jobs by running:</p>
<pre><code class="lang-bash">crontab -l
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-09-at-18.07.00.png" alt="Screen-Shot-2020-09-09-at-18.07.00" width="600" height="400" loading="lazy"></p>
<p>You can remove a cron job running <code>crontab -e</code> again, removing the line and exiting the editor:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-09-at-18.07.40.png" alt="Screen-Shot-2020-09-09-at-18.07.40" width="600" height="400" loading="lazy"></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-09-at-18.07.49.png" alt="Screen-Shot-2020-09-09-at-18.07.49" width="600" height="400" loading="lazy"></p>
<h2 id="heading-the-linux-uname-command">The Linux <code>uname</code> command</h2>
<p>Calling <code>uname</code> without any options will return the Operating System codename:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-07-at-07.37.41.png" alt="Screen-Shot-2020-09-07-at-07.37.41" width="600" height="400" loading="lazy"></p>
<p>The <code>m</code> option shows the hardware name (<code>x86_64</code> in this example) and the <code>p</code> option prints the processor architecture name (<code>i386</code> in this example):</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-07-at-07.37.51.png" alt="Screen-Shot-2020-09-07-at-07.37.51" width="600" height="400" loading="lazy"></p>
<p>The <code>s</code> option prints the Operating System name. <code>r</code> prints the release, and <code>v</code> prints the version:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-07-at-07.37.56.png" alt="Screen-Shot-2020-09-07-at-07.37.56" width="600" height="400" loading="lazy"></p>
<p>The <code>n</code> option prints the node network name:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-07-at-07.38.01.png" alt="Screen-Shot-2020-09-07-at-07.38.01" width="600" height="400" loading="lazy"></p>
<p>The <code>a</code> option prints all the information available:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-07-at-07.38.06.png" alt="Screen-Shot-2020-09-07-at-07.38.06" width="600" height="400" loading="lazy"></p>
<p>On macOS you can also use the <code>sw_vers</code> command to print more information about the macOS Operating System. Note that this differs from the Darwin (the Kernel) version, which above is <code>19.6.0</code>.</p>
<blockquote>
<p>Darwin is the name of the kernel of macOS. The kernel is the "core" of the Operating System, while the Operating System as a whole is called macOS. In Linux, Linux is the kernel, and GNU/Linux would be the Operating System name (although we all refer to it as "Linux").</p>
</blockquote>
<h2 id="heading-the-linux-env-command">The Linux <code>env</code> command</h2>
<p>The <code>env</code> command can be used to pass environment variables without setting them on the outer environment (the current shell).</p>
<p>Suppose you want to run a Node.js app and set the <code>USER</code> variable to it.</p>
<p>You can run</p>
<pre><code class="lang-bash">env USER=flavio node app.js
</code></pre>
<p>and the <code>USER</code> environment variable will be accessible from the Node.js app via the Node <code>process.env</code> interface.</p>
<p>You can also run the command clearing all the environment variables already set, using the <code>-i</code> option:</p>
<pre><code class="lang-bash">env -i node app.js
</code></pre>
<p>In this case you will get an error saying <code>env: node: No such file or directory</code> because the <code>node</code> command is not reachable, as the <code>PATH</code> variable used by the shell to look up commands in the common paths is unset.</p>
<p>So you need to pass the full path to the <code>node</code> program:</p>
<pre><code class="lang-bash">env -i /usr/<span class="hljs-built_in">local</span>/bin/node app.js
</code></pre>
<p>Try with a simple <code>app.js</code> file with this content:</p>
<pre><code class="lang-js"><span class="hljs-built_in">console</span>.log(process.env.NAME)
<span class="hljs-built_in">console</span>.log(process.env.PATH)
</code></pre>
<p>You will see the output as</p>
<pre><code><span class="hljs-literal">undefined</span>
<span class="hljs-literal">undefined</span>
</code></pre><p>You can pass an env variable:</p>
<pre><code class="lang-bash">env -i NAME=flavio node app.js
</code></pre>
<p>and the output will be</p>
<pre><code>flavio
<span class="hljs-literal">undefined</span>
</code></pre><p>Removing the <code>-i</code> option will make <code>PATH</code> available again inside the program:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-10-at-16.55.17.png" alt="Screen-Shot-2020-09-10-at-16.55.17" width="600" height="400" loading="lazy"></p>
<p>The <code>env</code> command can also be used to print out all the environment variables. If run with no options:</p>
<pre><code class="lang-bash">env
</code></pre>
<p>it will return a list of the environment variables set, for example:</p>
<pre><code class="lang-txt">HOME=/Users/flavio
LOGNAME=flavio
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
PWD=/Users/flavio
SHELL=/usr/local/bin/fish
</code></pre>
<p>You can also make a variable inaccessible inside the program you run, using the <code>-u</code> option. For example this code removes the <code>HOME</code> variable from the command environment:</p>
<pre><code class="lang-bash">env -u HOME node app.js
</code></pre>
<h2 id="heading-the-linux-printenv-command">The Linux <code>printenv</code> command</h2>
<p>Here's a quick guide to the <code>printenv</code> command, used to print the values of environment variables</p>
<p>In any shell there are a good number of environment variables, set either by the system, or by your own shell scripts and configuration.</p>
<p>You can print them all to the terminal using the <code>printenv</code> command. The output will be something like this:</p>
<pre><code class="lang-txt">HOME=/Users/flavio
LOGNAME=flavio
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
PWD=/Users/flavio
SHELL=/usr/local/bin/fish
</code></pre>
<p>with a few more lines, usually.</p>
<p>You can append a variable name as a parameter, to only show that variable value:</p>
<pre><code class="lang-bash">printenv PATH
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-10-at-16.31.20.png" alt="Screen-Shot-2020-09-10-at-16.31.20" width="600" height="400" loading="lazy"></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Thanks a lot for reading this handbook.</p>
<p>I hope it will inspire you to learn more about Linux and its capabilities. It's evergreen knowledge that will not be out of date any time soon.</p>
<p>Remember that you can <a target="_blank" href="https://flaviocopes.com/page/linux-commands-handbook/">download this handbook in PDF / ePUB / Mobi format</a> if you want!</p>
<p>I <strong>publish programming tutorials</strong> every day on my website <a target="_blank" href="https://flaviocopes.com">flaviocopes.com</a> if you want to check out more great content like this.</p>
<p>You can reach me on Twitter <a target="_blank" href="https://twitter.com/flaviocopes">@flaviocopes</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Grep Command Tutorial – How to Search for a File in Linux and Unix with Recursive Find ]]>
                </title>
                <description>
                    <![CDATA[ By Dillion Megida grep stands for Globally Search For Regular Expression and Print out. It is a command line tool used in UNIX and Linux systems to search a specified pattern in a file or group of files. grep comes with a lot of options which allow u... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/grep-command-tutorial-how-to-search-for-a-file-in-linux-and-unix/</link>
                <guid isPermaLink="false">66d84efcda89a73e2ddf5794</guid>
                
                    <category>
                        <![CDATA[ command line ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Linux ]]>
                    </category>
                
                    <category>
                        <![CDATA[ unix ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 13 May 2020 22:56:11 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9c9b0c740569d1a4ca2969.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Dillion Megida</p>
<p><code>grep</code> stands for <em>Globally Search For Regular Expression and Print out</em>. It is a command line tool used in UNIX and Linux systems to search a specified pattern in a file or group of files.</p>
<p><code>grep</code> comes with a lot of options which allow us to perform various search-related actions on files. In this article, we'll look at how to use <code>grep</code> with the options available as well as basic regular expressions to search files.</p>
<h2 id="heading-how-to-use-grep">How to use <code>grep</code></h2>
<p>Without passing any option, <code>grep</code> can be used to search for a pattern in a file or group of files. The syntax is:</p>
<pre><code class="lang-bash">grep <span class="hljs-string">'&lt;text-to-be-searched&gt;'</span> &lt;file/files&gt;
</code></pre>
<p><strong>Note that</strong> single or double quotes are required around the text if it is more than one word.</p>
<p>You can also use the <strong>wildcard (*)</strong> to select all files in a directory.</p>
<p>The result of this is the occurences of the pattern (by the line it is found) in the file(s). If there is no match, no output will be printed to the terminal. </p>
<p>For example, say we have the following files (called grep.txt):</p>
<pre><code class="lang-default">Hello, how are you
I am grep
Nice to meet you
</code></pre>
<p>The following <code>grep</code> command will search for all occurences of the word 'you':</p>
<pre><code class="lang-bash">grep you grep.txt
</code></pre>
<p>The result for this is:</p>
<pre><code class="lang-bash">Hello, how are you
Nice to meet you
</code></pre>
<p><code>you</code> is expected to have a different color than the other text to easily identify what was searched for.</p>
<p>But <code>grep</code> comes with more options which help us achieve more during a search operation. Let's look at nine of them while applying them to the example above.</p>
<h3 id="heading-options-used-with-grep">Options used with <code>grep</code></h3>
<h4 id="heading-1-n-line-number-list-line-numbers">1. <code>-n</code> (--line-number) - list line numbers</h4>
<p>This prints out the matches for the text along with the line numbers. If you look at the result we have above, you'll notice there are no line numbers, just the matches.</p>
<pre><code class="lang-bash">grep you grep.txt -n
</code></pre>
<p>Result:</p>
<pre><code class="lang-bash">1: Hello, how are you
3: Nice to meet you
</code></pre>
<h4 id="heading-2-c-count-prints-the-number-of-lines-of-matches">2. <code>-c</code> (--count) - prints the number of lines of matches</h4>
<pre><code class="lang-bash">grep you grep.txt -c
</code></pre>
<p>Result:</p>
<pre><code class="lang-bash">2
</code></pre>
<p><strong>Note that</strong> if there was another 'you' on line one, option <code>-c</code> would still print 2. This is because it is concerned with the number of lines where the matches appear, not the number of matches.</p>
<h4 id="heading-3-v-invert-match-prints-the-lines-that-do-not-match-the-specified-pattern">3. <code>-v</code> (--invert-match) - prints the lines that do not match the specified pattern</h4>
<pre><code class="lang-bash">grep you grep.txt -v -n
</code></pre>
<p>Result:</p>
<pre><code class="lang-bash">2. I am grep
</code></pre>
<p>Notice that we also used option <code>-n</code>? Yes, you can apply multiple options in one command.</p>
<h4 id="heading-4-i-ignore-case-used-for-case-insensitivity">4. <code>-i</code> (--ignore-case) - used for case insensitivity</h4>
<pre><code class="lang-bash"><span class="hljs-comment"># command 1</span>
grep You grep.txt
<span class="hljs-comment"># command 2</span>
grep YoU grep.txt -i
</code></pre>
<p>Results:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># result 1</span>
<span class="hljs-comment"># no result</span>
<span class="hljs-comment"># result 2</span>
Hello, how are you
Nice to meet you
</code></pre>
<h4 id="heading-5-l-files-with-matches-print-file-names-that-match-a-pattern">5. <code>-l</code> (--files-with-matches) - print file names that match a pattern</h4>
<pre><code class="lang-bash"><span class="hljs-comment"># command 1</span>
grep you grep.txt -l
<span class="hljs-comment"># command 2</span>
grep You grep.txt -i -l
</code></pre>
<p>Results:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># result 1</span>
grep.txt
<span class="hljs-comment"># result 2</span>
<span class="hljs-comment"># all files in the current directory that matches</span>
<span class="hljs-comment"># the text 'You' case insensitively</span>
</code></pre>
<h4 id="heading-6-w-word-regexp-print-matches-of-the-whole-word">6. <code>-w</code> (--word-regexp) - print matches of the whole word</h4>
<p>By default, <code>grep</code> matches strings which contain the specified pattern. This means that <code>grep yo grep.txt</code> will print the same results as <code>grep yo grep.txt</code> because 'yo' can be found in you. Similarly, 'ou'. </p>
<p>With the option <code>-w</code>, <code>grep</code> ensures that the matches are exactly the same pattern as specified. Example:</p>
<pre><code class="lang-bash">grep yo grep.txt -w
</code></pre>
<p>Result:</p>
<p>No result!</p>
<h4 id="heading-7-o-only-matching-print-only-the-matched-pattern">7. <code>-o</code> (--only-matching) - print only the matched pattern</h4>
<p>By default, <code>grep</code> prints the line where the matched pattern is found. With option <code>-o</code>, only the matched pattern is printed line by line. Example:</p>
<pre><code class="lang-bash">grep yo grep.txt -o
</code></pre>
<p>Result:</p>
<pre><code class="lang-bash">yo
</code></pre>
<h4 id="heading-8-a-after-context-and-b-before-context-print-the-lines-after-and-before-respectively-the-matched-pattern">8. <code>-A</code> (--after-context) and <code>-B</code> (--before-context) - print the lines after and before (respectively) the matched pattern</h4>
<pre><code class="lang-bash">grep grep grep.txt -A 1 -B 1
</code></pre>
<p>Result:</p>
<pre><code class="lang-bash">Hello, how are you
I am grep
Nice to meet you
</code></pre>
<p>This matched pattern is on line 2. <code>-A 1</code> means one line after the matched line and <code>-B 1</code> means one line before the matched line.</p>
<p>There's also a <code>-C</code> (--context) option which is equal to <code>-A</code> + <code>-B</code>. The value passed to <code>-C</code> would be used for <code>-A</code> and <code>-B</code>.</p>
<h4 id="heading-9-r-dereference-recursive-recursive-search">9. <code>-R</code> (--dereference-recursive) - recursive search</h4>
<p>By default, <code>grep</code> cannot search directories. If you try doing so, you'll get an error ("Is a directory"). With option <code>-R</code>, searching files within directories and subdirectories becomes possible. Example:</p>
<pre><code class="lang-bash">grep you .
</code></pre>
<p>Result:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># 'you' matches in a folders</span>
<span class="hljs-comment"># and files starting from the</span>
<span class="hljs-comment"># current directory</span>
</code></pre>
<h3 id="heading-regular-expressions-for-patterns">Regular expressions for patterns</h3>
<p><code>grep</code> also allows basic regular expressions for specifying patterns. Two of them are:</p>
<h4 id="heading-1-pattern-start-of-a-line">1. <code>^pattern</code> - start of a line</h4>
<p>This pattern means that the <code>grep</code> will match the strings whose lines begin with the string specified after <code>^</code>. Example:</p>
<pre><code class="lang-bash">grep ^I grep.txt -n
</code></pre>
<p>Result:</p>
<pre><code class="lang-bash">2: I
</code></pre>
<h4 id="heading-2-pattern-end-of-a-line">2. <code>pattern$</code> - end of a line</h4>
<p>In contrast with <code>^</code>, <code>$</code> specifies patterns that will be matched if the line ends with the string before <code>$</code>. Example:</p>
<pre><code class="lang-bash">grep you$ grep.txt
</code></pre>
<p>Result:</p>
<pre><code class="lang-bash">1: Hello, how are you
3: Nice to meet you
</code></pre>
<h2 id="heading-wrap-up">Wrap up</h2>
<p><code>grep</code> is a powerful tool for searching files in the terminal. Understanding how to use it gives you the ability to easily find files via the terminal. </p>
<p>There are more options attached to this tool. You can find with <code>man grep</code>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Symlink Tutorial in Linux – How to Create and Remove a Symbolic Link ]]>
                </title>
                <description>
                    <![CDATA[ By Dillion Megida A symlink (also called a symbolic link) is a type of file in Linux that points to another file or a folder on your computer. Symlinks are similar to shortcuts in Windows. Some people call symlinks "soft links" – a type of link in Li... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/symlink-tutorial-in-linux-how-to-create-and-remove-a-symbolic-link/</link>
                <guid isPermaLink="false">66d84f5d7211ea6be29e1b5d</guid>
                
                    <category>
                        <![CDATA[ Linux ]]>
                    </category>
                
                    <category>
                        <![CDATA[ unix ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sat, 02 May 2020 20:51:39 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9c9b4f740569d1a4ca2b02.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Dillion Megida</p>
<p>A symlink (also called a symbolic link) is a type of file in Linux that points to another file or a folder on your computer. Symlinks are similar to shortcuts in Windows.</p>
<p>Some people call symlinks "soft links" – a type of link in Linux/UNIX systems – as opposed to "hard links."</p>
<h2 id="heading-difference-between-a-soft-link-and-a-hard-link">Difference Between a Soft Link and a Hard Link</h2>
<p>Soft links are similar to shortcuts, and can point to another file or directory in any file system.</p>
<p>Hard links are also shortcuts for files and folders, but a hard link cannot be created for a folder or file in a different file system.</p>
<p>Let's look at the steps involved in creating and removing a symlink. We'll also see what broken links are, and how to delete them.</p>
<h2 id="heading-how-to-create-a-symlink">How to Create a Symlink</h2>
<p>The syntax for creating a symlink is:</p>
<pre><code class="lang-shell">ln -s &lt;path to the file/folder to be linked&gt; &lt;the path of the link to be created&gt;
</code></pre>
<p><code>ln</code> is the link command. The <code>-s</code> flag specifies that the link should be soft. <code>-s</code> can also be entered as <code>-symbolic</code>.</p>
<p>By default, <code>ln</code> command creates hard links. The next argument is <code>path to the file (or folder)</code> that you want to link. (That is, the file or folder you want to create a shortcut for.) </p>
<p>And the last argument is the <code>path to link</code> itself (the shortcut).</p>
<h2 id="heading-how-to-create-a-symlink-for-a-file-example-command">How to Create a Symlink for a File – Example Command</h2>
<pre><code class="lang-shell">ln -s /home/james/transactions.txt trans.txt
</code></pre>
<p>After running this command, you will be able to access the <code>/home/james/transactions.txt</code> with <code>trans.txt</code>. Any modification to <code>trans.txt</code> will also be reflected in the original file.</p>
<p>Note that this command above would create the link file <code>trans.txt</code> in your current directory. You can as well create a linked file in a folder link this:</p>
<pre><code class="lang-shell">ln -s /home/james/transactions.txt my-stuffs/trans.txt
</code></pre>
<p>There must be a directory already called "my-stuffs" in your current directory – if not the command will throw an error.</p>
<h2 id="heading-how-to-create-a-symlink-for-a-folder-example-command">How to Create a Symlink for a Folder – Example Command</h2>
<p>Similar to above, we'd use:</p>
<pre><code class="lang-shell">ln -s /home/james james
</code></pre>
<p>This would create a symlinked folder called 'james' which would contain the contents of <code>/home/james</code>. Any changes to this linked folder will also affect the original folder.</p>
<h2 id="heading-how-to-remove-a-symlink">How to remove a symlink</h2>
<p>Before you'd want to remove a symlink, you may want to confirm that a file or folder is a symlink, so that you do not tamper with your files. </p>
<p>One way to do this is:</p>
<pre><code class="lang-shell">ls -l &lt;path-to-assumed-symlink&gt;
</code></pre>
<p>Running this command on your terminal will display the properties of the file. In the result, if the first character is a small letter L ('l'), it means the file/folder is a symlink.</p>
<p>You'd also see an arrow (-&gt;) at the end indicating the file/folder the simlink is pointing to.</p>
<p>There are two methods to remove a symlink:</p>
<h3 id="heading-how-to-use-unlink-to-remove-a-symlink">How to Use Unlink to Remove a Symlink</h3>
<p>The syntax is:</p>
<pre><code class="lang-shell">unlink &lt;path-to-symlink&gt;
</code></pre>
<p>This deletes the symlink if the process is successful.</p>
<p>Even if the symlink is in the form of a folder, do not append '/', because Linux will assume it's a directory and <code>unlink</code> can't delete directories.</p>
<h3 id="heading-how-to-use-rm-to-remove-a-symlink">How to use rm to Remove a Symlink</h3>
<p>As we've seen, a symlink is just another file or folder pointing to an original file or folder. To remove that relationship, you can remove the linked file.</p>
<p>Hence, the syntax is:</p>
<pre><code class="lang-shell">rm &lt;path-to-symlink&gt;
</code></pre>
<p>For example:</p>
<pre><code class="lang-shell">rm trans.txt
rm james
</code></pre>
<p>Note that trying to do <code>rm james/</code> would result an error, because Linux will assume 'james/' is a directory, which would require other options like <code>r</code> and <code>f</code>. But that's not what we want. A symlink may be a folder, but we are only concerned with the name.</p>
<p>The main benefit of <code>rm</code> over <code>unlink</code> is that you can remove multiple symlinks at once, like you can with files.</p>
<h2 id="heading-how-to-find-and-delete-broken-links">How to Find and Delete Broken Links</h2>
<p>Broken links occur when the file or folder that a symlink points to changes path or is deleted.</p>
<p>For example, if 'transactions.txt' moves from <code>/home/james</code> to <code>/home/james/personal</code>, the 'trans.txt' link becomes broken. Every attempt to access to the file will result in a 'No such file or directory' error. This is because the link has no contents of its own.</p>
<p>When you discover broken links, you can easily delete the file. An easy way to find broken symlinks is:</p>
<pre><code class="lang-shell">find /home/james -xtype l
</code></pre>
<p>This will list all broken symlinks in the <code>james</code> directory – from files to directories to sub-directories.</p>
<p>Passing the <code>-delete</code> option will delete them like so:</p>
<pre><code class="lang-shell">find /home/james -xtype l -delete
</code></pre>
<h2 id="heading-wrapping-up">Wrapping up</h2>
<p>Symbolic link are an interesting feature of Linux and UNIX systems. </p>
<p>You can create easily accessible symlinks to refer to a file or folder that would otherwise not be convenient to access. With some practice, you will understand how these work on an intuitive level, and they will make you much more efficient at managing file systems.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ BSD Operating System ]]>
                </title>
                <description>
                    <![CDATA[ Berkeley Software Distribution (BSD) is a group of related open source Unix-like operating systems (OS) with origins in early versions of Research Unix at Bell Labs. FreeBSD is the most popular member. BSD is configured for internet hosting, web host... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/bsd-operating-system/</link>
                <guid isPermaLink="false">66c3464a8ced2460cf9e9b5b</guid>
                
                    <category>
                        <![CDATA[ BSD ]]>
                    </category>
                
                    <category>
                        <![CDATA[ toothbrush ]]>
                    </category>
                
                    <category>
                        <![CDATA[ unix ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sat, 01 Feb 2020 00:00:00 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9c9d2b740569d1a4ca364c.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Berkeley Software Distribution (BSD) is a group of related open source Unix-like operating systems (OS) with origins in early versions of Research Unix at Bell Labs. FreeBSD is the most popular member.</p>
<p>BSD is configured for internet hosting, web hosting, and hosting many servers on one system. It is the first OS to have added an internet protocol. BSD OSes have a very strongly enforced time-sharing system, which makes them most useful where resources are shared between processes. </p>
<p>As a comparison, the Linux OS is known to be preferred for single-task processes such as supercomputers and desktops. The effective BSD multi-tasking forced-interrupt part of timesharing gets in the way of dedicated single processes.</p>
<p>BSD includes a ‘Jails’ system which is somewhat analogous to Linux Containers —except with additional security and flexibility in implementation.</p>
<h3 id="heading-more-information"><strong>More Information:</strong></h3>
<ul>
<li><a target="_blank" href="https://en.wikipedia.org/wiki/FreeBSD">FreeBSD (Wikipedia.org)</a></li>
<li><a target="_blank" href="https://en.wikipedia.org/wiki/OpenBSD">OpenBSD (Wikipedia.org)</a></li>
<li><a target="_blank" href="https://en.wikipedia.org/wiki/NetBSD">NetBSD (Wikipedia.org)</a></li>
<li><a target="_blank" href="https://en.wikipedia.org/wiki/Comparison_of_BSD_operating_systems">Comparison of BSD operating systems (Wikipedia.org)</a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use SFTP to Securely Transfer Files with a Remote Server ]]>
                </title>
                <description>
                    <![CDATA[ This article is a quick tutorial on how to use Secure File Transfer Protocol (SFTP) to exchange files with a server. This is useful for programming, as it allows you to code and test locally, and then send your work to the server when you are done. T... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-use-sftp-to-securely-transfer-files-with-a-remote-server/</link>
                <guid isPermaLink="false">66c355d371e87702d4e5b697</guid>
                
                    <category>
                        <![CDATA[ command line ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Linux ]]>
                    </category>
                
                    <category>
                        <![CDATA[ toothbrush ]]>
                    </category>
                
                    <category>
                        <![CDATA[ unix ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sat, 01 Feb 2020 00:00:00 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9c9d1c740569d1a4ca35f2.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>This article is a quick tutorial on how to use Secure File Transfer Protocol (SFTP) to exchange files with a server. This is useful for programming, as it allows you to code and test locally, and then send your work to the server when you are done.</p>
<h3 id="heading-testing-ssh"><strong>Testing SSH</strong></h3>
<p>If you haven’t already, test that you are able to SSH into the server. SFTP uses the Secure Shell (SSH) protocol, so if you are unable to SSH you probably won’t be able to SFTP either.</p>
<pre><code class="lang-unix">ssh your_username@hostname_or_ip_address
</code></pre>
<h3 id="heading-start-sftp-session"><strong>Start SFTP Session</strong></h3>
<p>This uses the same syntax as SSH and opens a session in which you can transfer files.</p>
<pre><code class="lang-unix">sftp your_username@hostname_or_ip_address
</code></pre>
<p>To list helpful commands:</p>
<pre><code class="lang-unix">help
</code></pre>
<h3 id="heading-transfer-files-and-folders"><strong>Transfer files and folders</strong></h3>
<p>To download a file:</p>
<pre><code class="lang-unix">get &lt;filename&gt;
</code></pre>
<p>To download a folder and its contents, use the “-r” flag (also works for uploading):</p>
<pre><code class="lang-unix">get -r &lt;foldername&gt;
</code></pre>
<p>To upload a file:</p>
<pre><code class="lang-unix">put &lt;filename&gt;
</code></pre>
<h3 id="heading-change-folders"><strong>Change folders</strong></h3>
<p>To change the local folder:</p>
<pre><code class="lang-unix">lcd &lt;path/to/folder&gt;
</code></pre>
<p>To change the remote folder:</p>
<pre><code class="lang-unix">cd &lt;path/to/folder&gt;
</code></pre>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Program design in the Unix environment: an academic article summary ]]>
                </title>
                <description>
                    <![CDATA[ By Shubheksha Jalan Today, let’s take a look at “Program Design in the Unix Environment” published in 1983 by Pike and Kernighan. The paper opens by listing why Unix has been successful, and then comments on the Unix philosophy and its benefits. It d... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/program-design-in-the-unix-environment-a-summary-cadcb8816dcf/</link>
                <guid isPermaLink="false">66d46106768263422736e8bb</guid>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ software development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ summary ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ unix ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sun, 28 Jan 2018 20:29:12 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/0*O-H_d2lDRBmnCgFG.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Shubheksha Jalan</p>
<p>Today, let’s take a look at “<a target="_blank" href="http://harmful.cat-v.org/cat-v/unix_prog_design.pdf">Program Design in the Unix Environment</a>” published in 1983 by Pike and Kernighan.</p>
<p>The paper opens by listing why Unix has been successful, and then comments on the <a target="_blank" href="https://en.wikipedia.org/wiki/Unix_philosophy">Unix philosophy</a> and its benefits. It does so by looking at examples where programs diverged from the Unix philosophy and discussing the resulting trade offs</p>
<p>The reasons for Unix’s success:</p>
<ol>
<li>Portability: the kernel &amp; applications were written in C, so they could be moved from system to system without being re-written in the assembly language particular to that system.</li>
<li>The same OS ran on different hardware, so the users were already familiar and didn’t have to relearn when new hardware was released.</li>
<li>The vendors could ship the same software with each machine despite changes in hardware.</li>
<li>The system was not too big and was easy to modify since everything was written in C.</li>
<li>It provided a new philosophy based on the use of general purpose tools. They did one thing well and could be combined to do a particular task, instead of creating giant monolithic tools that served only one purpose.</li>
</ol>
<p>The paper argues that the use and design of tools is closely related, and how they fit together is the main subject of this essay.</p>
<p>The paper then dives into <code>cat</code> (the Unix command line utility for concatenating and printing files). It copies its input to its output. The input is usually a sequence of one or more files or the standard input. The output is a file or the standard output.</p>
<p>The main purpose of <code>cat</code> was to act as a utility to concatenate files. It can be combined with the pipe (<code>|</code>) operator to further enhance and extend its utility through output redirection.</p>
<p>Other systems, on the other hand, try to dump a bunch of related functionality into a single command which is against the Unix philosophy. It also creates a lock-in of functionality that might be useful to other programs.</p>
<p>Advantages of the Unix approach:</p>
<ol>
<li>The shell and the programs it can invoke provide uniform access to system facilities. Eg: the filename arguments are expanded by the shell in a similar fashion for each command. Because of pipes, we don’t need every command to deal with pre- and post- processing of input.</li>
<li>Growth is easy when functions are well-separated.</li>
</ol>
<p>Example: the `(backtic) operator was added to convert the output of one program into the input of another without requiring changes in any other program as it is interpreted by the shell. All programs the shell invokes acquire this feature automatically. If each program that required this feature interpreted it, it’d be very hard to enforce uniformity and carry out further experimentation, as each new idea would affect all the programs that would want to use it.</p>
<p>However, in future versions of <code>cat</code>, many new options were introduced (such as printing line numbers and non-printable characters).</p>
<p>The authors argue that instead of adding those options to <code>cat</code> itself, either existing programs should’ve been used or new programs should’ve been created. For example, line number functionality could’ve been provided by using <code>pr</code>. However, there was no program which allowed printing of non-printable characters which warranted the creation of a new one.</p>
<blockquote>
<p>Such a modification confuses what <code>cat</code>’s job is  concatenating files  with<br>what it happens to do in a common special case  showing a file on the terminal. A UNIX program should do one thing well, and leave unrelated tasks to other programs. <code>cat</code>’s job is to collect the data in files. Programs that collect data shouldn’t change the data; <code>cat</code> therefore shouldn’t transform its input.</p>
</blockquote>
<p>Whenever we split something into multiple programs, we sacrifice some efficiency. But since <code>cat</code> is usually used without any options, it makes sense to have the most common cases be the most efficient.</p>
<blockquote>
<p>Separate programs are not always better than wider options; which is better depends on the problem. Whenever one needs a way to perform a new function, one faces the choice of whether to add a new option or write a new program (assuming that none of the programmable tools will do the job conveniently). The<br>guiding principle for making the choice should be that each program does one thing. Options are appropriately added to a program that already has the right functionality. If there is no such program, then a new program is called for. In that case, the usual criteria for program design should be used: the program should be as general as possible, its default behavior should match the most common usage, and it should cooperate with other programs.</p>
</blockquote>
<p>Let’s consider another issue: dealing with fast terminal lines. How do we deal with output from <code>cat</code> scrolling off the top of the screen?</p>
<p>There are two approaches:</p>
<ol>
<li>Tell each command about terminal properties so it does the right thing</li>
<li>Write a command that handles only terminals without modifying other programs</li>
</ol>
<p>Let’s consider examples of both approaches: <code>lsc</code> and <code>ls</code> which prints out the list of files in a directory.</p>
<p><code>lsc</code> varies its output depending on the input. It displays the list in a columnar fashion across the screen so that the o/p fits if it’s outputting to the terminal. <code>ls</code> displays everything in a single column.</p>
<blockquote>
<p>By retaining single column output to files or pipes, <code>lsc</code> ensures compatibility with programs like <code>grep</code> or <code>wc</code> that expect things to be printed one per line. This ad-hoc adjustment of the output format depending on the destination is not only distasteful, it is unique  no standard UNIX command has this property.</p>
</blockquote>
<p>The authors argue that the columnation facility is useful in general and shouldn’t be locked away in just <code>lsc</code> , making it inaccessible to other programs. They advocate for a different program whose primary job is columnation.</p>
<blockquote>
<p>Similar reasoning suggests a solution for the general problem of data flowing off screens (columnated or not): a separate program to take any input and print it a screen at a time. Such programs are by now widely available, under names like pg and more. This solution affects no other programs, but can be used with all of them. As usual, once the basic feature is right, the program can be enhanced with options…</p>
</blockquote>
<p>Based on the previous example, the authors also talk about different cases where some functionality is locked away in a specific program (like input history in the terminal) which would be better off as a central service. All interactive programs could benefit from it.</p>
<p>They conclude with how augmenting existing commands with features/options is not desirable in Unix, it goes against its basic philosophy: make a program do one thing well. Several such programs can be composed to accomplish a more complex task.</p>
<blockquote>
<p>The key to problem solving on the UNIX system is to identify the right primitive operations and to put them at the right place. UNIX programs tend to solve general problems rather than special cases. In a very loose sense, the programs are orthogonal, spanning the space of jobs to be done (although with a fair<br>amount of overlap for reasons of history, convenience or efficiency). Functions are placed where they will do the most good: there shouldn’t be a pager in every program that produces output any more than there should be filename pattern matching in every program that uses filenames.</p>
<p>One thing that UNIX does not need is more features. It is successful in part because it has a small number of good ideas that work well together. Merely adding features does not make it easier for users to do things  it just makes the manual thicker. The right solution in the right place is always more effective<br>than haphazard hacking.</p>
</blockquote>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Conquering the Command Line ]]>
                </title>
                <description>
                    <![CDATA[ By Monica Powell A brief guide to getting started on UNIX/Mac OS terminal When I was first introduced to the command line I really had to adjust to navigating my computer in a black box with just text. So I avoided the command line as much as possibl... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/conquering-the-command-line-f85f5e46c07c/</link>
                <guid isPermaLink="false">66c347d7eb0555cdb6fd9ae9</guid>
                
                    <category>
                        <![CDATA[ mac ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                    <category>
                        <![CDATA[ terminal ]]>
                    </category>
                
                    <category>
                        <![CDATA[ unix ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 05 Dec 2017 17:11:11 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*NvuIEr51nwGNxv7O3TXcpA.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Monica Powell</p>
<h4 id="heading-a-brief-guide-to-getting-started-on-unixmac-os-terminal">A brief guide to getting started on UNIX/Mac OS terminal</h4>
<p>When I was first introduced to the command line I really had to adjust to navigating my computer in a black box with just text. So I avoided the command line as much as possible. I was accustomed to the visual cues and feedback that a computer usually provides. In many ways it felt like I was re-learning how to use a computer via the command line.</p>
<p>Yet, since first learning how to navigate my computer using UNIX commands I’ve learned that the command line doesn’t have to be a scary thing just because there’s no visual feedback when typing a password in on the command line. As security, nothing shows up as you type in your password to indicate that any characters have been entered.</p>
<h4 id="heading-what-is-the-command-line">What is the command line?</h4>
<p>The command line is a software that executes commands or instructions for a computer to manipulate or interact with its file system.</p>
<h3 id="heading-what-is-unix">What is UNIX?</h3>
<h4 id="heading-why-use-the-command-line">Why Use the Command Line?</h4>
<ul>
<li>Faster to modify, navigate between files</li>
<li>Able to install software as a superuser</li>
<li>Can see hidden dotfiles<br>dotfiles are UNIX configuration files, they tend to be files that are proceeded with a <code>.</code> and are hidden to normal users.<br>You can <a target="_blank" href="https://medium.com/@webprolific/getting-started-with-dotfiles-43c3602fd789">learn more about getting started with dotfiles in this article</a>).</li>
</ul>
<p>In order to get started on the command line you should navigate to your applications and open the <strong>Terminal</strong> application.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0wX7Il6ZWb4qFXWhJ1rAvbrEAquvv0mWSDcV" alt="Image" width="100" height="100" loading="lazy">
<em>Above is the Terminal Icon on Mac.</em></p>
<h3 id="heading-create-a-basic-website-folder-on-the-command-line">Create a Basic Website Folder on the Command Line</h3>
<p><img src="https://cdn-media-1.freecodecamp.org/images/q-nEv8AuA5alFW0jj8uEDZfN7Re2bCsyWNbV" alt="Image" width="166" height="141" loading="lazy">
<em>Folder structure of sample project</em></p>
<p>A folder with the above structure can be create on the command line by typing the commands inside of an empty directory:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/skROBs72rmbM9R19Xll-9fVTzLXZoEi1VHrc" alt="Image" width="770" height="439" loading="lazy">
<em>We start inside of an empty directory!</em></p>
<ul>
<li>Make a directory (also known as a folder) called personal-website<br><code>mkdir personal-website</code></li>
</ul>
<p><img src="https://cdn-media-1.freecodecamp.org/images/nXYWE7E1AQgDoGiFXHYRmmop7jAGy7HR7Xt-" alt="Image" width="766" height="438" loading="lazy">
<em>We’ve created a folder named personal-website</em></p>
<ul>
<li>Navigate to inside of the directory called personal-website<br><code>cd personal-website</code></li>
<li>create a directory, inside of the personal-website folder called assets<br><code>mkdir assets</code></li>
</ul>
<p><img src="https://cdn-media-1.freecodecamp.org/images/hwOipEstl7aPZxV1youY746JZnJqcuv8j5VU" alt="Image" width="764" height="438" loading="lazy">
<em>We’ve created a folder inside of personal-website to contain all of our assets</em></p>
<ul>
<li>Navigate inside of the assets folder which is inside of the personal-website folder<br><code>cd assets</code></li>
<li>create a directory, inside of the assets folder named images<br><code>mdkir images</code></li>
<li>create a directory, inside of the assets folder named js<br><code>mkdir js</code></li>
<li>create a directory, inside of the assets folder named css<br><code>mkdir css</code></li>
</ul>
<p><img src="https://cdn-media-1.freecodecamp.org/images/VjWywXJ3fXn8IIUSS1rUS82fWBelN6qVwg28" alt="Image" width="764" height="437" loading="lazy">
<em>We’ve created folders inside of personal-website/assets to store our project’s assets</em></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/loq-rOeylfEFovUlcja88GAhSSXTq4JRjjbC" alt="Image" width="166" height="141" loading="lazy"></p>
<p>Woops! We forgot to create an index.html file :(</p>
<p>We are in the assets folder and want an index.html file in our main personal-website folder. Typing <code>cd ..</code> will move us out of the assets folder and into the directory above which is personal-website. Now that we are in the personal-website folder if we type <code>touch index.html</code> a blank index.html file will be created.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/ws7T-u5nT2AWqrsKAipU2E5upuEmeN18gCC5" alt="Image" width="231" height="158" loading="lazy"></p>
<h3 id="heading-some-frequently-used-terminal-commands-are">Some frequently used terminal commands are:</h3>
<h4 id="heading-commands-to-navigatemanipulate-the-filesystem">commands to navigate/manipulate the filesystem</h4>
<p><strong>ls</strong><br> <strong>list</strong> the contents of a directory</p>
<p><strong>pwd</strong><br><strong>print working directory</strong> for the terminal to display the directory you are currently working on</p>
<p><strong>touch</strong><br>create or open a file without making any changes<br>very handy when wanting to create empty files without leaving the command line</p>
<p><strong>sudo</strong><br>this allows you to run commands as a <strong>super user</strong></p>
<p><strong>mv</strong><br><strong>move</strong> a file or directory<br>this can be used to move or rename a file by updating the file path</p>
<p><strong>cd</strong><br><strong>change the current directory</strong> you are working on so that you can access files on a different part of the system<br><code>cd</code> moves you to the root directory (top level folder on computer — usually the current User)<br><code>cd .</code> current directory<br><code>cd ..</code> navigates to directory two levels up</p>
<p><strong>mkdir</strong><br><strong>make</strong> a new <strong>directory</strong> (or a folder)</p>
<h4 id="heading-commands-to-install-software"><strong>Commands to Install Software</strong></h4>
<p>You can install some software from the command line using the following commands:</p>
<ul>
<li>in Python <code>pip install &lt;package nam</code>e&gt;.<br>Pip is a software package manager for Python.</li>
<li>in JavaScript <code>npm install &lt;package na</code>me&gt;<br>NPM is a package manager for JavaScript pages.</li>
</ul>
<h4 id="heading-commands-to-run-software">Commands to Run Software</h4>
<p>In order to run a script on the command line you need to provide a command prompt and file name. Some examples are:</p>
<ul>
<li>in Java <code>javac filename.java</code> and then <code>java filename</code> compiles java projects and then runs them.</li>
<li>in Python <code>python filename</code> runs python scripts.</li>
</ul>
<p>If you find you are repeating a lot of commands you can scroll through your recent commands using the up/down arrows and edit them and re-run by navigating to them and then pressing enter.</p>
<h4 id="heading-additional-resources-to-get-started-with-command-line-prompts">Additional Resources to Get Started with Command Line Prompts</h4>
<ul>
<li><a target="_blank" href="http://web.mit.edu/mprat/Public/web/Terminus/Web/main.html">MIT Terminus (interactive game to learn command line)</a></li>
<li><a target="_blank" href="https://www.codecademy.com/learn/learn-the-command-line">Codecademy Learn the Command Line</a></li>
<li><a target="_blank" href="https://learnpythonthehardway.org/book/appendixa.html">Learn Python the Hard Way’s Command Line Crash Course</a></li>
</ul>
<h4 id="heading-decorating-the-command-line">Decorating the Command Line</h4>
<p>You can completely customize the colors and outputs on the command line to better suit your visual and aesthetic needs.</p>
<p>Here’s how I’ve made my command line prettier :</p>
<p>How to install Tomorrow Night<br><a target="_blank" href="https://github.com/chriskempson/tomorrow-theme/blob/master/OS%20X%20Terminal/Tomorrow%20Night.terminal">https://github.com/chriskempson/tomorrow-theme/blob/master/OS%20X%20Terminal/Tomorrow%20Night.terminal</a></p>
<p><a target="_blank" href="https://mindthecode.com/customize-the-terminal/"><strong>Customize the terminal</strong></a><br><a target="_blank" href="https://mindthecode.com/customize-the-terminal/">_I love the terminal. Besides the fact it makes you look awesome while using it, it can also do about a gazillion…_mindthecode.com</a></p>
<p><em>If you enjoyed reading this article consider tapping the clap button ?. Wanna see more of my work? Check out m<a target="_blank" href="https://github.com/M0nica/">y GitHub</a> to view my code and learn more about my development experience at h<a target="_blank" href="http://aboutmonica.com">ttp://aboutmonica.com.</a></em></p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
