<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: J Edwards</title>
    <description>The latest articles on Forem by J Edwards (@joaedwar).</description>
    <link>https://forem.com/joaedwar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F414420%2F6ed62340-ac32-4a32-9612-c2b4e10e35a3.jpeg</url>
      <title>Forem: J Edwards</title>
      <link>https://forem.com/joaedwar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/joaedwar"/>
    <language>en</language>
    <item>
      <title>Va Va Vim: Get Going With the Vim Text Editor</title>
      <dc:creator>J Edwards</dc:creator>
      <pubDate>Sun, 03 Jan 2021 23:47:22 +0000</pubDate>
      <link>https://forem.com/joaedwar/getting-started-with-vim-editor-31g</link>
      <guid>https://forem.com/joaedwar/getting-started-with-vim-editor-31g</guid>
      <description>&lt;p&gt;Introduction&lt;br&gt;
Installation&lt;br&gt;
Modes&lt;br&gt;
Commands&lt;br&gt;
Resources&lt;/p&gt;


&lt;h1&gt;
  
  
  What is Vim?
&lt;/h1&gt;

&lt;p&gt;Vim (Vi IMproved) is an open-source text editor. It is a clone of &lt;a href="https://www.thegeekdiary.com/basic-vi-commands-cheat-sheet/"&gt;vi&lt;/a&gt; and is designed for use both from a command-line interface (CLI) and as a standalone application in a graphical user interface (GUI).&lt;/p&gt;

&lt;p&gt;The vi editor, the first screen-oriented text editor developed by Billy Joy in 1976, was created for Unix environments and built for text manipulation. &lt;/p&gt;

&lt;p&gt;Based on his work for Stevie &lt;a href="https://en.wikipedia.org/wiki/Stevie_(text_editor)"&gt;(ST Editor for VI Enthusiasts)&lt;/a&gt;, Bram Moolenaar developed and publicly released Vim (v1.14) in 1991.&lt;/p&gt;

&lt;p&gt;Initially, the name &lt;em&gt;Vim&lt;/em&gt; was an acronym for "Vi IMitation", but that changed to "'Vi IMproved" in 1993.&lt;/p&gt;

&lt;p&gt;Vim supports more features than vi, is very configurable, and enables efficient text editing.&lt;/p&gt;
&lt;h1&gt;
  
  
  Why Use Vim?
&lt;/h1&gt;

&lt;p&gt;Vim and similar text editors are incredibly powerful. By learning it, you gain the ability to navigate and modify files expertly and efficiently.&lt;/p&gt;

&lt;p&gt;According to &lt;a href="https://cmd.com/blog/vim-or-emacs-the-debate-is-over/"&gt;cmd.com&lt;/a&gt;, most of their users use vi/Vim as their primary file editor, with the breakdown corresponding with following statistics: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.vim.org/"&gt;vi/Vim&lt;/a&gt;: 93%&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.howtogeek.com/howto/42980/the-beginners-guide-to-nano-the-linux-command-line-text-editor/"&gt;nano&lt;/a&gt;: 5%&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.redhat.com/sysadmin/beginners-guide-emacs"&gt;Emacs&lt;/a&gt;: 2%&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In Vim, all edits are saved, and you can load past revisions easily. If you make a mistake, you can look through the list of previous versions, and select the version that works best for you. &lt;/p&gt;

&lt;p&gt;Vim's features include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;an extensive plugin system&lt;/li&gt;
&lt;li&gt;integration with many tools&lt;/li&gt;
&lt;li&gt;support for hundreds of programming languages and file formats&lt;/li&gt;
&lt;li&gt;a powerful search and replace&lt;/li&gt;
&lt;/ul&gt;


&lt;h1&gt;
  
  
  Install Vim
&lt;/h1&gt;

&lt;p&gt;To install Vim, enter the following command: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ubuntu / Debian&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo apt install vim 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;CentOS&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo yum install vim
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Fedora&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo dnf install vim
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After Vim is installed, you can open the editor by typing the following command in the terminal:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This command opens the default page that displays the Vim version number.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YTN49Guy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/9za5r5oukh8rslghrst1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YTN49Guy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/9za5r5oukh8rslghrst1.png" alt="Default page of Vim with version number" width="335" height="227"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Vim Modes
&lt;/h1&gt;

&lt;p&gt;Vim is a &lt;em&gt;modal&lt;/em&gt; text editor. Based on the vi editor, Vim inherits the key bindings of vi, but also adds more functionality and extensibility that is missing from the original vi text editor.&lt;/p&gt;

&lt;p&gt;In Vim, the mode that the editor is in determines whether the alphanumeric keys will input characters or facilitate navigation throughout the document.&lt;/p&gt;

&lt;p&gt;Vim has several different editing modes, but its basic modes are:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Normal mode&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This mode is used for editor commands. This is usually designated as the default mode.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Visual mode&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Similar to Normal mode, this mode is used to highlight areas of text. Normal commands run on the highlighted area, which can be used to move or edit a selection.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Insert mode&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This mode is similar to editing in most editors. In Insert mode, you can input characters and modify files.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EOyJGFbc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/quhh0v3ycpmpmd3fzkyi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EOyJGFbc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/quhh0v3ycpmpmd3fzkyi.png" alt="Switch between Insert mode and Visual mode" width="770" height="135"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cmdline mode&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This is the command-line mode and supports a single line input at the bottom of the Vim window. Commands beginning with &lt;code&gt;:&lt;/code&gt; activate this mode.&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Vim Commands
&lt;/h1&gt;

&lt;p&gt;All Vim commands can be carried out using the keyboard - although some can be executed through the command line, while others can be used as navigation keys. This allows you to keep your fingers on the keyboard and your eyes on the screen. &lt;/p&gt;

&lt;p&gt;To learn more about the various commands and actions that can be used in Vim, use the &lt;code&gt;help.txt&lt;/code&gt; file. It can be accessed in Vim with the F1 key or with the &lt;code&gt;:help&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;In the meantime, here are a few basic commands to get started with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Switching Between Modes&lt;/li&gt;
&lt;li&gt;Navigation Keys&lt;/li&gt;
&lt;li&gt;Basic Commands for Normal Mode&lt;/li&gt;
&lt;li&gt;Basic Commands for Insert Mode&lt;/li&gt;
&lt;li&gt;Executing in Command Mode&lt;/li&gt;
&lt;li&gt;Search and Replace Command&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Switch Modes
&lt;/h3&gt;

&lt;p&gt;By default, Vim starts in Normal mode. Normal mode can be accessed from other modes by pressing Esc.&lt;/p&gt;

&lt;p&gt;To switch Vim to Insert mode, press i. &lt;/p&gt;

&lt;p&gt;Press v to enter Visual mode. &lt;/p&gt;

&lt;h3&gt;
  
  
  Navigation Keys
&lt;/h3&gt;

&lt;p&gt;There are multiple ways to move around in an open file. In addition to using the cursor keys, you can use the keys in the table below to navigate through a file in Vim. &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Key&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;h&lt;/td&gt;
&lt;td&gt;Left by one character&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;j&lt;/td&gt;
&lt;td&gt;Down by one row&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;k&lt;/td&gt;
&lt;td&gt;Up by one row&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;l&lt;/td&gt;
&lt;td&gt;Right by one character&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;w&lt;/td&gt;
&lt;td&gt;Move one word to the right&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;W&lt;/td&gt;
&lt;td&gt;Move one word to the right past punctuation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;b&lt;/td&gt;
&lt;td&gt;Move one word to the left&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;B&lt;/td&gt;
&lt;td&gt;Move one word to the left past punctuation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;H&lt;/td&gt;
&lt;td&gt;Move to the top of the current screen&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;M&lt;/td&gt;
&lt;td&gt;Move to the middle of the current screen&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;L&lt;/td&gt;
&lt;td&gt;Move to the bottom of the current screen&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;Row movement can be prefixed by a number to move several lines at a time. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Basic Normal Mode Commands
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Command&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;d&lt;/td&gt;
&lt;td&gt;Delete the text that is selected&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
dk
&lt;/td&gt;
&lt;td&gt;Delete the current line and the line above it. d ↑ can also be used.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;x&lt;/td&gt;
&lt;td&gt;Delete only the current character under the cursor&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
cc
&lt;/td&gt;
&lt;td&gt;Delete the current line and change to Insert mode&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
yy&lt;/td&gt;
&lt;td&gt;Copy the selected text&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;p&lt;/td&gt;
&lt;td&gt;Paste the copied content&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;u&lt;/td&gt;
&lt;td&gt;Undo the last edit. Press u again for further undos&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;U&lt;/td&gt;
&lt;td&gt;Undo changes on the current line&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Ctrlr
&lt;/td&gt;
&lt;td&gt;Redo a change undone by u
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;You can combine keys to specify movement. For example,  dw deletes the first word on the right side of the cursor. It also copies the content, so that you can paste it to another location. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Basic Insert Mode Commands
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Command&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;a&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Insert characters to the right of the cursor&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;A&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Append characters to the current line&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;i&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Insert characters to the left of cursor&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;I&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Insert characters at the beginning of the current line&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;o&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Add a new line after the current line&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;O&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Insert a new line above the current line&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Basic Command Mode Commands
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Command&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;:q!&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Quit but do not save changes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;:w!&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Force save the file&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;:wq&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Save the file and exit Vim&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;:w&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Write out the file to save changes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;:w &amp;lt;file_name&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Write the file to the specified file&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;:r &amp;lt;file_name&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Import a file into the current file&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;You can prefix commands with a number to couple navigation. For instance, &lt;code&gt;:10 r &amp;lt;file_name&amp;gt;&lt;/code&gt; imports a file into the current file after line 10.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Search and Replace Command
&lt;/h3&gt;

&lt;p&gt;To perform a basic search and replace function, use the following format in an editable mode:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;%s/&amp;lt;search_term&amp;gt;/&amp;lt;replace_term&amp;gt;/g 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command replaces all instances of the &lt;em&gt;search_term&lt;/em&gt; with the &lt;em&gt;replace_term&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;To breakdown the command:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;:&lt;/code&gt; enters command mode&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;%&lt;/code&gt; means across all lines&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;s&lt;/code&gt; means to substitute&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Optionally, you can use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;/foo&lt;/code&gt; is the regex (regular expression) to find things to replace&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/bar/&lt;/code&gt; is the regex to replace things with&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/g&lt;/code&gt; means global, otherwise, the command will only execute once per line&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;c&lt;/code&gt; to confirm each replacement&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Vim has a number of other methods that you can read about in the help documentation, by entering the command &lt;code&gt;:h&lt;/code&gt; or &lt;code&gt;:help&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For instance, if given the text file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello world
You are my sunshine
In the world
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the command &lt;code&gt;:%s/world/planet/g/c&lt;/code&gt; is executed, all instances of &lt;em&gt;world&lt;/em&gt; are changed to &lt;em&gt;planet&lt;/em&gt;. The new file will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello planet
You are my sunshine
In the planet
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;c&lt;/code&gt; at the end of the command, prompts a confirmation message, and you will be asked if you want to proceed with the replacement. &lt;/p&gt;




&lt;h1&gt;
  
  
  Resources
&lt;/h1&gt;

&lt;p&gt;Vim is a great, powerful, and very learnable tool. Becoming comfortable with the basics of Vim (or similar text editors) helps in becoming a more confident developer. &lt;/p&gt;

&lt;p&gt;The are several amazing resources that can help you get better-acquainted and familiar with Vim. Check out the following links to learn more about using Vim as a text editor, as well as some of the available plugins that can be used with it.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://vimdoc.sourceforge.net/htmldoc/intro.html#vim-modes-intro"&gt;A Thorough Introduction to Vim&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://catswhocode.com/vim-commands/"&gt;Essential Vim Commands&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://rawgit.com/darcyparker/1886716/raw/vimModeStateDiagram.svg"&gt;Vim Mode Visualization&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.openvim.com/"&gt;Vim Tutorial&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.tecmint.com/vi-vim-inspired-code-editors-for-linux/"&gt;vi/Vim - Inspired Code Editors for Linux&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://learnbyexample.gitbooks.io/vim-reference/content/Introduction.html"&gt;Vim Reference&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>vim</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Git Gremlin: Squash Commits (to Make Your Git History Cleaner)</title>
      <dc:creator>J Edwards</dc:creator>
      <pubDate>Fri, 01 Jan 2021 23:50:46 +0000</pubDate>
      <link>https://forem.com/joaedwar/git-gremlin-squash-commits-to-make-your-git-history-cleaner-gjn</link>
      <guid>https://forem.com/joaedwar/git-gremlin-squash-commits-to-make-your-git-history-cleaner-gjn</guid>
      <description>&lt;p&gt;Git is a free and open-source distributed version control system, designed to help developers handle small to large code changes with efficiency. But, &lt;em&gt;with great ease comes great opportunity for screw-ups&lt;/em&gt;.  It is quite easy (especially for beginners) to make a small mistake with Git that can have a seemingly catastrophic effect on overall work. Some Git mistakes are more intimidating and difficult to correct than others, but fear not! There is no need to panic — you can roll back a Git disaster with some help.  For the &lt;em&gt;infinite&lt;/em&gt; number of ways one can make an error with Git, &lt;strong&gt;Git Gremlin&lt;/strong&gt; provides useful tips for what to do when things don't go as planned.&lt;/p&gt;




&lt;ul&gt;
&lt;li&gt;User Story&lt;/li&gt;
&lt;li&gt;Scenario&lt;/li&gt;
&lt;li&gt;
Issue &lt;/li&gt;
&lt;li&gt;Resolution&lt;/li&gt;
&lt;li&gt;Prerequisites&lt;/li&gt;
&lt;li&gt;Procedure&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  User Story
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;As an open-source contributor, I want to group the content of a pull request, so that the commit history is neater&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Scenario
&lt;/h2&gt;

&lt;p&gt;When working with Git, you may want to revise your local commit history and decide what files go into which commits. &lt;br&gt;
You can rewrite commits so they appear as if they occurred in a different manner. This can involve changing the order of the commits, changing messages, modifying files in a commit, or removing commits entirely , before you share your work with other contributors who have access to the repository. &lt;/p&gt;

&lt;p&gt;For example, after using &lt;code&gt;git log&lt;/code&gt; to view the commit history, you notice some embarrassing commits on a feature branch, similar to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* ed88dab Correct configuration details
* dca37d5 typo
* 46e83b5 test
* e30e77d undo mistake
* 9409777 Add configuration details
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You want to rework the history so that the output from &lt;code&gt;git log&lt;/code&gt; looks more like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* ed88dab Add Test and correct configuration details
* 9409777 Add configuration details
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What is the Issue?
&lt;/h3&gt;

&lt;p&gt;How can you augment the commit history so that a series of &lt;em&gt;N&lt;/em&gt; commits are presented in a single commit?&lt;/p&gt;




&lt;h3&gt;
  
  
  How to Resolve the Issue?
&lt;/h3&gt;

&lt;p&gt;Squashing can be used to condense a large number of commits into a smaller number of more meaningful commits, in an effort to make the git history clearer.&lt;/p&gt;

&lt;p&gt;Squashing in Git is a technique that employs &lt;em&gt;rebasing&lt;/em&gt; to help consolidate a series of commits. You can use &lt;code&gt;git rebase&lt;/code&gt; to combine a sequence of commits into a new base commit. When you use rebasing to rewrite history, you are automatically applying commits in your current working branch to the passed branch head. &lt;/p&gt;

&lt;p&gt;By making the rebase interactive (adding the &lt;code&gt;-i&lt;/code&gt; option to &lt;code&gt;git rebase&lt;/code&gt;) you have the opportunity to alter individual commits.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git rebase --interactive&lt;/code&gt; (&lt;code&gt;-i&lt;/code&gt; for short), opens an editor with a list of the commits which can be changed as well as a  list of acceptable commands - allowing the user to edit the list before initiating the rebase action. In addition to squashing a commit, the user is also presented with the following options:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;p, pick = use commit
r, reword = use commit, but edit the commit message
e, edit = use commit, but stop for amending
s, squash = use commit, but meld into previous commit
f, fixup = like “squash”, but discard this commit’s log message
x, exec = run command (the rest of the line) using shell
d, drop = remove commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Prerequisites
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;A branch with a commit history.&lt;/li&gt;
&lt;li&gt;You will need to use the terminal to execute commands. &lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Procedure
&lt;/h4&gt;

&lt;p&gt;Use the following command to get the commit history:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;The output will reflect the commits on that branch, similar to the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* 617c65c Fix CRD group and minor updates
* 46e95a5 WIP additional work in progress
* e30e77d WIP work in progress
* 9409666 Adding the build script
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are WIP (Work in Progress) commits in the history that we can squash to make the Git history more concise. To interactively rebase the commits, we can use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git rebase -i HEAD~&amp;lt;n&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Alternatively, you can use the command &lt;br&gt;
&lt;code&gt;git rebase -i &amp;lt;after-this-commit-sha1&amp;gt;&lt;/code&gt;. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The &lt;code&gt;-i&lt;/code&gt; flag in the command indicates that is an interactive rebase and the &lt;code&gt;&amp;lt;n&amp;gt;&lt;/code&gt; represents the number of commits you want to go back in your history to rewrite.&lt;/p&gt;

&lt;p&gt;In our example, we would like to rebase all commits proceeding the initial commit, and can use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git rebase -i HEAD~3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An interactive editor opens when the rebase process commences. The rebase command brings up an interface that presents the following options:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pick 617c65c Fix CRD group and minor updates
pick 46e95a5 WIP additional work in progress
pick e30e77d WIP work in progress

# Rebase 617c65c..e30e77d onto e30e77d (3 command(s))
# 
# Commands:
# p, pick &amp;lt;commit&amp;gt; = use commit
# r, reword &amp;lt;commit&amp;gt; = use commit, but edit the commit message
# e, edit &amp;lt;commit&amp;gt; = use commit, but stop for amending
# s, squash &amp;lt;commit&amp;gt; = use commit, but meld into previous commit
# f, fixup &amp;lt;commit&amp;gt; = like "squash", but discard this commit's log message
# x, exec &amp;lt;command&amp;gt; = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop &amp;lt;commit&amp;gt; = remove commit
# l, label &amp;lt;label&amp;gt; = label current HEAD with a name
# t, reset &amp;lt;label&amp;gt; = reset HEAD to a label
# m, merge [-C &amp;lt;commit&amp;gt; | -c &amp;lt;commit&amp;gt;] &amp;lt;label&amp;gt; [# &amp;lt;oneline&amp;gt;]
# .       create a merge commit using the original merge commit's
# .       message (or the oneline, if no original merge commit was
# .       specified). Use -c &amp;lt;commit&amp;gt; to reword the commit message.

#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The editor displays the commits in reverse order starting from &lt;em&gt;3&lt;/em&gt; commits back, which is defined by &lt;code&gt;HEAD~3&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the editor, replace &lt;code&gt;pick&lt;/code&gt; (on all commit lines except the top line) with &lt;code&gt;squash&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pick 617c65c Fix CRD group and minor updates
squash 46e95a5 WIP additional work in progress
squash e30e77d WIP work in progress
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;squash&lt;/code&gt; command consolidates the three commits into the top commit.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Alternatively, you can use the &lt;code&gt;fixup&lt;/code&gt; command and amend the commit message.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To save changes and exit the interactive editor, press Esc, enter &lt;code&gt;:&lt;/code&gt; followed by &lt;code&gt;x&lt;/code&gt;, and press Enter.&lt;/p&gt;

&lt;p&gt;If you view the output of &lt;code&gt;git log&lt;/code&gt; again, a single commit is displayed.&lt;/p&gt;




&lt;p&gt;That's it! If you'd like to dive deeper, please check out more of the &lt;em&gt;Git Gremlin&lt;/em&gt; posts. Also, the following resources are helpful for getting more comfortable with Git:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://git-scm.com/"&gt;Git-SCM&lt;/a&gt; - Git reference documentation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://training.github.com/"&gt;Git Training&lt;/a&gt; - Official Git cheat sheets &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://git-school.github.io/visualizing-git"&gt;Visual Git&lt;/a&gt; - A tool for exploring Git visually.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/jlord/git-it-electron"&gt;Git Game&lt;/a&gt; - A desktop application that helps you learn Git through fun challenges.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thank you for checking out this post, and please &lt;em&gt;git&lt;/em&gt; going!&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
    </item>
    <item>
      <title>Git Gremlin: Pull Request Fake Out (to Clean Up A Messy Pull Request)</title>
      <dc:creator>J Edwards</dc:creator>
      <pubDate>Tue, 29 Dec 2020 18:00:00 +0000</pubDate>
      <link>https://forem.com/joaedwar/git-gremlin-pull-request-fake-out-2ii8</link>
      <guid>https://forem.com/joaedwar/git-gremlin-pull-request-fake-out-2ii8</guid>
      <description>&lt;p&gt;Git is a free and open-source distributed version control system, designed to help developers handle small to large code changes with efficiency. But, &lt;em&gt;with great ease comes great opportunity for screw-ups&lt;/em&gt;. It is quite easy (especially for beginners) to make a small mistake with Git that can have a seemingly catastrophic effect on overall work. Some Git mistakes are more intimidating and difficult to correct than others, but fear not! There is no need to panic — you can roll back a Git disaster with some help.  For the &lt;em&gt;infinite&lt;/em&gt; number of ways one can make an error with Git, &lt;strong&gt;Git Gremlin&lt;/strong&gt; provides useful tips for what to do when things don't go as planned.&lt;/p&gt;




&lt;ul&gt;
&lt;li&gt;User Story&lt;/li&gt;
&lt;li&gt;Scenario&lt;/li&gt;
&lt;li&gt;
Issue &lt;/li&gt;
&lt;li&gt;Resolution&lt;/li&gt;
&lt;li&gt;Prerequisites&lt;/li&gt;
&lt;li&gt;Procedure&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  User Story
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;As a developer who has created a flawed pull request, I want to seamlessly change the content of a pull request and augment its history, so that my initial mistake is not visible in the commit history&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Scenario
&lt;/h3&gt;

&lt;p&gt;You are a new contributor to a repository and have just submitted a pull request (PR) that must be reviewed and approved by a maintainer to be merged. You created the initial pull request, it was reviewed, comments were left, and you added some additional commits. &lt;/p&gt;

&lt;p&gt;For whatever reason (maybe you accidentally pulled in additional commits during a rebase, or found an error in a commit you pushed to the PR) you want to completely change the content of the pull request, but do not want to close the pull request. You want to keep the history of the comments the maintainer left when reviewing your initial pull request, but also want to essentially rewrite the commit history and add entirely brand new content to the same pull request.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the Issue?
&lt;/h3&gt;

&lt;p&gt;How do you completely change the history and content of a single pull request, without closing it? Let's look at the example below.&lt;/p&gt;

&lt;p&gt;If the pull request looks like the following image:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdr1x720fo84by9lxk18z.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdr1x720fo84by9lxk18z.jpg" alt="Inital pull request with multiple commits and errors"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How can you clean up the pull request, so it looks more like this?&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4kjdls63lojumis9vh8f.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4kjdls63lojumis9vh8f.jpg" alt="Same pull request with a single new commit"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  How to Resolve the Issue?
&lt;/h3&gt;

&lt;p&gt;There are actually a number of ways you can approach this issue, but the following solution will employ a branch renaming strategy to solve the problem. &lt;/p&gt;

&lt;p&gt;For the solution, you are essentially faking the branching strategy. You will rename the original branch the pull request is on, create a new branch to add content to, and then rename the new branch with the original branch name. A bit confusing, but it's clarified in the steps below. &lt;/p&gt;
&lt;h4&gt;
  
  
  Prerequisites
&lt;/h4&gt;

&lt;p&gt;To get started you should have the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A pull request you want to change/work on.&lt;/li&gt;
&lt;li&gt;You should know which branch the pull request is being pushed into.&lt;/li&gt;
&lt;li&gt;You will need to use the terminal and your text editor. This is solution does not use the GitHub UI.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the procedure, the following is assumed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You have forked and cloned the repository you plan to work on. &lt;/li&gt;
&lt;li&gt;The remote branch is named &lt;code&gt;origin&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The name of the branch the pull request is on is &lt;code&gt;docs_restructure&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The pull request is being pushed to the &lt;code&gt;main&lt;/code&gt; branch (default branch). &lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Procedure
&lt;/h4&gt;

&lt;p&gt;To start, check which branch you are on by using &lt;code&gt;git status&lt;/code&gt;. You should see an output similar to the following after you enter the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git status
On branch docs_restructure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rename the original (current) branch&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git branch -M &amp;lt;ORIGINAL_BRANCH_NAME&amp;gt; &amp;lt;NEW_NAME&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example, you should enter a command similar to the &lt;br&gt;
following, if you're using &lt;code&gt;docs_restructure&lt;/code&gt; as the original branch name:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git branch -M docs_restructure docs_change
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After the branch has been renamed, you can verify the change has been applied by using &lt;code&gt;git status&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see an output similar to the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;On branch docs_change
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Switch to the default branch.  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In most repositories, this branch is labeled either &lt;code&gt;master&lt;/code&gt;, &lt;code&gt;main&lt;/code&gt;, &lt;code&gt;developer&lt;/code&gt;, or &lt;code&gt;development&lt;/code&gt;. In any case, it should be the branch that the pull request is being pushed to.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git checkout main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see an output similar to the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Switched to branch 'main'
Your branch is up to date with 'origin/main'.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, create an entirely new branch. This new branch is where you can add the content you want to appear in the pull request.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git checkout -b &amp;lt;NEW_BRANCH&amp;gt;

Switched to a new branch 'improvement_branch'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rename the new branch, so it has the original name of the branch the initial pull request was on.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git branch -M &amp;lt;NEW_BRANCH&amp;gt; &amp;lt;ORIGINAL_BRANCH_NAME&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example, you can use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git branch -M improvement_branch docs_restructure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The branch is now named &lt;code&gt;docs_restructure&lt;/code&gt; - the same as what you started with!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the text editor of your choice, make the changes that you would like to see in the pull request and save the content. &lt;/p&gt;

&lt;p&gt;Add the new content to the branch you are currently on.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git add .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Commit the changes. Be sure to leave a commit message that reflects the changes made.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git commit -m "restructure docs"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Push the changes to the branch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git push &amp;lt;REMOTE_NAME&amp;gt; &amp;lt;ORIGINAL_BRANCH_NAME&amp;gt; --force
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Following the examples used in this post, the command will look similar to the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git push origin docs_restructure --force
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;That's it! If you'd like to dive deeper, please check out more of the &lt;em&gt;Git Gremlin&lt;/em&gt; posts. Also, the following resources are helpful for getting more comfortable with Git:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://git-scm.com/" rel="noopener noreferrer"&gt;Git-SCM&lt;/a&gt; - Git reference documentation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://training.github.com/" rel="noopener noreferrer"&gt;Git Training&lt;/a&gt; - Official Git cheat sheets &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://git-school.github.io/visualizing-git" rel="noopener noreferrer"&gt;Visual Git&lt;/a&gt; - A tool for exploring Git visually.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/jlord/git-it-electron" rel="noopener noreferrer"&gt;Git Game&lt;/a&gt; - A desktop application that helps you learn Git through fun challenges.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thank you for checking out this post, and please &lt;em&gt;git&lt;/em&gt; going!&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
    </item>
    <item>
      <title>Getting Started with Kubernetes: A Brief Introduction to Kubernetes Pod Security Policies</title>
      <dc:creator>J Edwards</dc:creator>
      <pubDate>Sat, 05 Dec 2020 04:23:29 +0000</pubDate>
      <link>https://forem.com/joaedwar/getting-started-with-kubernetes-a-brief-introduction-to-kubernetes-pod-security-policies-2k7h</link>
      <guid>https://forem.com/joaedwar/getting-started-with-kubernetes-a-brief-introduction-to-kubernetes-pod-security-policies-2k7h</guid>
      <description>&lt;p&gt;&lt;em&gt;As a new user of Kubernetes, I want to understand how to create a pod security policy, so I can secure a Kubernetes cluster.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;Kubernetes is a powerful container management and orchestration platform that automates many of the manual processes involved in deploying, managing, and scaling containerized applications. When using Kubernetes (or really any container-centric management platform), security must take a central role in the deployment of your applications and services. &lt;/p&gt;

&lt;p&gt;Container security is the process of implementing security tools and policies that help you protect the infrastructure of your container and add the needed assurance that everything in your container is running as you intend. &lt;/p&gt;

&lt;p&gt;Because containers encapsulate all their dependencies and automation has shifted security across the software development lifecycle, securing containers has become a prominent issue in container management. Manually creating and maintaining security rules for each entity is impractical, so integrating security into CI/CD workflows and implementing DevSecOps best practices provides incredible security advantages in the world of containers.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Kubernetes pod security policies&lt;/em&gt; provide an efficient way to enforce security settings across a cluster. You can use &lt;a href="https://medium.com/better-programming/secure-your-kubernetes-cluster-with-pod-security-policies-bd511ec6d034"&gt;Pod Security Policies&lt;/a&gt; to keep Kubernetes and the containers running in it, secured.&lt;/p&gt;

&lt;p&gt;Read on to find out more about Kubernetes pod security policies and the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is a Pod?&lt;/li&gt;
&lt;li&gt;Creating a Kubernetes Pod Security Policy&lt;/li&gt;
&lt;li&gt;Understanding the structure of a Kubernetes Pod Security Policy&lt;/li&gt;
&lt;li&gt;Example: Create a Kubernetes Pod Security Policy that Prevents the Creation of Privileged Pods&lt;/li&gt;
&lt;li&gt;Verification&lt;/li&gt;
&lt;li&gt;Delete the policy&lt;/li&gt;
&lt;li&gt;The Takeaway&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  What is a Pod?
&lt;/h1&gt;

&lt;p&gt;A &lt;a href="https://kubernetes.io/docs/concepts/workloads/pods/"&gt;pod&lt;/a&gt; is the basic (and smallest) building block of Kubernetes &lt;a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/kubernetes-objects/"&gt;Objects&lt;/a&gt;. Within a cluster, a pod represents a process that is running. The inside of a pod can have one container or can have a co-located group of containers with shared resources, and specifications. Containers within a single pod share the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A unique network IP&lt;/li&gt;
&lt;li&gt;Network credentials&lt;/li&gt;
&lt;li&gt;Storage resources&lt;/li&gt;
&lt;li&gt;Specifications applied to the pod that govern how the container should run&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can scale your application by adding or removing pods. &lt;/p&gt;

&lt;p&gt;Now that we have introduced the concept of pods in Kubernetes, let's review how to craft a security policy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ytlnojqv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://anchore.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-01-at-4.32.42-PM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ytlnojqv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://anchore.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-01-at-4.32.42-PM.png" alt="Kubernetes logo and lock" width="800" height="363"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Creating a Kubernetes Pod Security Policy
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;Pod security policies&lt;/em&gt; (PSP) are specified in &lt;a href="https://rollout.io/blog/yaml-tutorial-everything-you-need-get-started/"&gt;YAML&lt;/a&gt; files. Note that YAML files are based on indentation with spaces, not with tabs.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; You can use &lt;code&gt;.yml&lt;/code&gt; or &lt;code&gt;.yaml&lt;/code&gt; extension for YAML files. Although the &lt;code&gt;.yaml&lt;/code&gt; extension is recommended, many code bases and documentation use &lt;code&gt;.yml&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The following is an example of a pod security policy YAML file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
  name: example
spec:
  privileged: false
  runAsUser:
    rule: MustRunAsNonRoot
  seLinux:
    rule: RunAsAny
  fsGroup:
    rule: RunAsAny
  supplementalGroups:
    rule: RunAsAny
  volumes:
  - 'nfs'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above &lt;code&gt;PodSecurityPolicy&lt;/code&gt; implements the following security rules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Disallows containers running in privileged mode.&lt;/li&gt;
&lt;li&gt;Disallows containers that require root privileges&lt;/li&gt;
&lt;li&gt;Disallows containers that access volumes apart from &lt;code&gt;NFS&lt;/code&gt; volumes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s take a closer look at the fields in a pod security policy. &lt;/p&gt;




&lt;h2&gt;
  
  
  Understanding the structure of a Kubernetes Pod Security Policy
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;metadata&lt;/code&gt; section of the policy specifies the name and basic information.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;spec&lt;/code&gt; section of the policy outlines the key criteria a pod must fulfill in order to be allowed to run.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Required Fields
&lt;/h2&gt;

&lt;p&gt;In the YAML file for the Kubernetes object you want to create, you'll need to set values for the following fields:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;apiVersion&lt;/code&gt; - version of the Kubernetes API you're using to create this object&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;kind&lt;/code&gt; - kind of object you want to create&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;metadata&lt;/code&gt; - data that helps uniquely identify the object&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;spec&lt;/code&gt; - the state you desire for the object&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Definitions of fields that you should understand to get started
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;privileged&lt;/code&gt; - indicates whether to allow containers 
that use &lt;em&gt;privileged mode&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;runAsUser&lt;/code&gt; - defines which users a container can run as. Most commonly, it is used to prevent pods from running as the root user.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;seLinux&lt;/code&gt;- defines the Security-Enhanced Linux (SELinux) security context for containers and only allows containers that match that context. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;supplementalGroups&lt;/code&gt;- defines which group IDs containers add.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;fsGroup&lt;/code&gt; - defines the user groups or fsGroup-owned volumes that a container may access. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;volumes&lt;/code&gt; - defines the type(s) of volumes a container may access. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;hostPorts&lt;/code&gt; - together with related fields like &lt;code&gt;hostNetwork&lt;/code&gt;, &lt;code&gt;hostPID&lt;/code&gt;, and &lt;code&gt;hostIPC&lt;/code&gt;, restrict the ports (and other networking capabilities) that a container may access on the host system.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To learn more about configuring these fields, please read the &lt;a href="https://kubernetes.io/docs/concepts/policy/pod-security-policy/#policy-reference"&gt;Kubernetes documentation&lt;/a&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  Assumptions for Creating a Pod Security Policy
&lt;/h3&gt;

&lt;p&gt;When a Kubernetes cluster is started with pod security policy support, Kubernetes follows a &lt;em&gt;default-deny&lt;/em&gt; approach. This means that, by default, pods are not allowed to run unless they match the criteria outlined in a pod security policy. This also means that if your cluster does not have at least one pod security policy in place, not a single pod will run and Kubernetes will let you know that you should activate a pod security policy. You should see an error message that reads the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;no providers available to validate pod request.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Kubernetes API is intent-based. Each API call allows you to specify the desired-state for one of Kubernetes’ many objects. To send this desired state to Kubernetes, use &lt;a href="https://kubernetes.io/docs/reference/kubectl/overview/"&gt;kubectl&lt;/a&gt;, the CLI for running commands against Kubernetes clusters. Use kubectl to apply the YAML file to your Kubernetes' cluster.&lt;br&gt;
You can use the following command to activate the newly created YAML file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl create -f &amp;lt;policy-name&amp;gt;.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; &lt;code&gt;&amp;lt;policy-name&amp;gt;.yaml&lt;/code&gt; denotes the policy file you created and plan to implement.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h4&gt;
  
  
  Prerequisites
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;You have a Kubernetes cluster running. &lt;/li&gt;
&lt;li&gt;You have kubectl command-line tool installed. &lt;/li&gt;
&lt;li&gt;You have enabled support for pod security policies. You can only use pod security policies if they are enabled in your Kubernetes cluster's admission controller.&lt;/li&gt;
&lt;li&gt;You should have some knowledge of Kubernetes and how things work in your cluster. Use the &lt;a href="https://kubernetes.io/docs/setup/"&gt;Getting Started&lt;/a&gt; documentation as a resource. &lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;To better explain how pod security policies work in practice, the following example walks you through creating a security policy.&lt;/p&gt;




&lt;h3&gt;
  
  
  Example: Create a Kubernetes Pod Security Policy that Prevents the Creation of Privileged Pods
&lt;/h3&gt;

&lt;p&gt;In a Kubernetes pod, containers can optionally run in &lt;em&gt;privileged&lt;/em&gt; mode, which means that the processes inside the container have almost unrestricted access to resources on the host system. Although there are some use cases where this level of access is necessary, in general, it’s a security risk to let your containers do this.&lt;/p&gt;

&lt;p&gt;You can create a Kubernetes pod security policy that prevents the creation of privileged pods and controls access to volumes. To do this, create the YAML file that defines the specifications of your policy. &lt;/p&gt;

&lt;p&gt;You can prevent privileged containers from running by including the following in your Kubernetes pod security policy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
  name:no-privileged-containers
spec:
  privileged: false
  runAsUser:
    rule: MustRunAsNonRoot
  seLinux:
    rule: RunAsAny
  supplementalGroups:
    rule: RunAsAny
  fsGroup:
    rule: RunAsAny  
  volumes:
  - '*'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the file, you are preventing privileged pods with the line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;privileged: false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The following is also allowed in this pod security policy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Allows any user to control &lt;code&gt;SELinux&lt;/code&gt; within pods&lt;/li&gt;
&lt;li&gt;Allows users to run container entry points only as a non-root user&lt;/li&gt;
&lt;li&gt;Volumes support ownership management&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next, activate the policy by executing the following command, which creates the new policy from the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl create -f no-privileged-containers.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check that the policy has been installed with the following command, which lists all active policies in the cluster:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get psp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see the policy listed, along with its specifications. &lt;/p&gt;

&lt;h3&gt;
  
  
  Verification
&lt;/h3&gt;

&lt;p&gt;After you activate the policy, you should test it. Try running a container that contradicts the rules established in the policy. This provides a way to check that your specifications are in place and working. &lt;/p&gt;

&lt;p&gt;In the &lt;code&gt;no-privileged-containers.yaml&lt;/code&gt;, since the pod security policy explicitly disallows pods or containers with root privileges, a request to do the opposite should be rejected. You should see an error output similar to the following example when you check the pod's status.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you enter the command: &lt;br&gt;
  &lt;code&gt;kubectl get pods&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;The output, if unsuccessful, should be similar to:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; container has runAsNonRoot and image will run as root
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Delete the Policy
&lt;/h3&gt;

&lt;p&gt;You can delete the &lt;code&gt;no-privileged-containers&lt;/code&gt; pod security policy with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl delete psp no-privileged-containers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  The Takeaway
&lt;/h1&gt;

&lt;p&gt;In this article, we've looked at creating a pod security policy and addressed the various fields included in the YAML file of the policy. You should now be able to create, check the status, verify and delete a Kubernetes pod security policy. &lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Pod security policy is a cluster-level resource that controls security sensitive aspects of the pod specification.&lt;/li&gt;
&lt;li&gt;YAML files are pretty specific, but also quite easy to create.&lt;/li&gt;
&lt;li&gt;If ever in doubt, check out the official &lt;a href="https://kubernetes.io/docs/home/"&gt;Kubernetes&lt;/a&gt; documentation for helpful tips and examples.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So now...go forth and start securing your cluster.&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>beginners</category>
      <category>security</category>
      <category>containers</category>
    </item>
    <item>
      <title>Tackling the Terminal: Introduction to the Command Line</title>
      <dc:creator>J Edwards</dc:creator>
      <pubDate>Tue, 20 Oct 2020 00:42:24 +0000</pubDate>
      <link>https://forem.com/joaedwar/tackling-the-terminal-introduction-to-the-command-line-3kho</link>
      <guid>https://forem.com/joaedwar/tackling-the-terminal-introduction-to-the-command-line-3kho</guid>
      <description>&lt;p&gt;If you're new to Linux... start here.&lt;/p&gt;

&lt;p&gt;Beginning your journey into the exciting world of Linux can be daunting (and at times a bit overwhelming). To get a good foothold on Linux and to start on your way towards being an active contributor, it is essential you understand the basics of the operating system. To become familiar with what's under the hood in your Linux OS, it is crucial you understand how to navigate its filesystem.&lt;/p&gt;

&lt;p&gt;A computer’s filesystem organizes the data stored on a computer so that it can be easily retrieved by a user. Files are typically represented by a tree-like structure, in which any parent directory can have any number of children. The root directory is then found at the base of the tree.&lt;/p&gt;

&lt;p&gt;The command line allows a user to navigate the Linux filesystem and run programs or custom scripts. In Linux, the command line interface is called Bash, and the shell prompt is usually &lt;code&gt;$&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This article goes over the absolute basics of traversing the Linux filesystem.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bash Background&lt;/li&gt;
&lt;li&gt;
Getting around the File Directory

&lt;ul&gt;
&lt;li&gt;Print the Working Directory&lt;/li&gt;
&lt;li&gt;List Files&lt;/li&gt;
&lt;li&gt;Make a Directory&lt;/li&gt;
&lt;li&gt;Change the Directory&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
Manipulating the File Directory

&lt;ul&gt;
&lt;li&gt;Remove Files&lt;/li&gt;
&lt;li&gt;Move Files&lt;/li&gt;
&lt;li&gt;Copy Files&lt;/li&gt;
&lt;/ul&gt;


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

&lt;h3&gt;
  
  
  Bash Background
&lt;/h3&gt;

&lt;p&gt;The Bourne-Again Shell (Bash) was developed by the Free Software Foundation (FSF) under the GNU Project. Although Bash is the default user shell on most Linux installations, it is just one of several well-known UNIX shells. Still, its wide distribution with Linux makes it an important tool to learn.&lt;/p&gt;

&lt;p&gt;The UNIX shell allows users to interact effectively with the system through the command-line interface (CLI). A shell action can invoke an executable that causes the kernel to create a new running process. The shell can send the output of one program as the input into another and facilitate interaction with the filesystem - so users can move around and make changes to files by using the command line.&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting around the File Directory
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Print Working Directory
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;pwd&lt;/code&gt; - The shell command &lt;code&gt;pwd&lt;/code&gt; displays the file path from the root directory to the current working directory.
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  List
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ls&lt;/code&gt; - The shell command &lt;code&gt;ls&lt;/code&gt; is used to list the contents of directories. If no arguments are given, it will list the contents of the current working directory.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ls Desktop
assignment.pdf
photo.png
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Options can be used to modify the behavior of shell commands. Shell command options are commonly represented by a single letter preceded by a &lt;code&gt;-&lt;/code&gt;. &lt;/p&gt;

&lt;h4&gt;
  
  
  List Command Options
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-a&lt;/code&gt;: lists all contents, including hidden files and directories.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-l&lt;/code&gt;: lists all contents, in long format.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-t&lt;/code&gt;: lists all contents, by the time they were last modified.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-r&lt;/code&gt;: lists and the contents of the directory in reverse sorting order.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-R&lt;/code&gt;: lists the contents of all directories below the current directory recursively.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-S&lt;/code&gt;: sorts files by sizes.&lt;/li&gt;
&lt;li&gt;Additionally, multiple options can be used together.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ls -a
$ ls -l
$ ls -t
$ ls -alt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Make Directory
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;mkdir&lt;/code&gt; - The shell command &lt;code&gt;mkdir&lt;/code&gt; can be used to make a new directory in the filesystem according to its argument. If a file path is given, the new directory will be placed at the end. Otherwise, it will create a new directory in the current working directory with the name given.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mkdir new-directory
$ ls 
old-directory    new-directory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Change Directory
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;cd&lt;/code&gt; - The shell command &lt;code&gt;cd&lt;/code&gt; can be used to navigate through the filesystem of a computer. You can use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Full file paths.&lt;/li&gt;
&lt;li&gt;Names of the children of the current directory.&lt;/li&gt;
&lt;li&gt;It's important to understand the characters that have special functionality in the Linux filesystem:&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The dot (&lt;code&gt;.&lt;/code&gt;) represents the current directory in the filesystem.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The dot-dot (&lt;code&gt;..&lt;/code&gt;) represents one level above the current directory. It is the parent of the current directory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The forward-slash (&lt;code&gt;/&lt;/code&gt;) represents the "root" of the filesystem. Every directory/file in the Linux filesystem is nested under the &lt;code&gt;root/directory&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The tilde (&lt;code&gt;~&lt;/code&gt;) represents the home directory of the currently logged-in user.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;So, you can move to the filesystem’s root (&lt;code&gt;/&lt;/code&gt;) with this command:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;


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

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;To navigate back to your home directory:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cd ~
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Manipulating the File Directory
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Remove
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;rm&lt;/code&gt; - The shell command &lt;code&gt;rm&lt;/code&gt; is used to delete files and directories. The &lt;code&gt;-r&lt;/code&gt; flag deletes a directory and all of its files and directories.
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Move
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;mv&lt;/code&gt; - The shell command &lt;code&gt;mv&lt;/code&gt; is used to move a file into a directory or to rename a file. Use &lt;code&gt;mv&lt;/code&gt; with the source file as the first argument and the destination directory as the second argument.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mv index.html website/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;You can use the &lt;code&gt;mv&lt;/code&gt; command to rename a file or directory
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mv old_name new_name
# The above command renames the file `old_name` to `new_name`.

mv ../old_name new_name
# The above command moves the file `old_name` from one directory up to the current directory and renames it `new_name`.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Copy
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;cp&lt;/code&gt; - The shell command &lt;code&gt;cp&lt;/code&gt; is used to copy files or directories.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cp file1 file1_copy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>beginners</category>
      <category>linux</category>
      <category>bash</category>
    </item>
  </channel>
</rss>
