<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ashutosh Patole</title>
    <description>The latest articles on DEV Community by Ashutosh Patole (@ashutoshpatole).</description>
    <link>https://dev.to/ashutoshpatole</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%2F652918%2F57c0564e-4514-43ec-b20d-25ece204a871.jpeg</url>
      <title>DEV Community: Ashutosh Patole</title>
      <link>https://dev.to/ashutoshpatole</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ashutoshpatole"/>
    <language>en</language>
    <item>
      <title>change directory command</title>
      <dc:creator>Ashutosh Patole</dc:creator>
      <pubDate>Mon, 21 Jun 2021 04:41:49 +0000</pubDate>
      <link>https://dev.to/ashutoshpatole/change-directory-command-47ld</link>
      <guid>https://dev.to/ashutoshpatole/change-directory-command-47ld</guid>
      <description>&lt;p&gt;This is my first blog on this platform. 😁&lt;br&gt;
I have written this post keeping non linux users in mind. Just to make sure that they understand it clearly. Let's start the linux journey. &lt;/p&gt;

&lt;p&gt;We might face the situation where we have to navigate the file system through a terminal or cmd because of lack of GUI  feature in the system like Servers. So it is must to know the basics of &lt;code&gt;cd&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;cd command means Change Directory which is kind of self explanatory term. Now before jumping into the examples there is something we should know i.e, &lt;code&gt;Paths&lt;/code&gt; in file system.&lt;/p&gt;

&lt;p&gt;There are two types of paths in any operating system. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Absolute Path&lt;/li&gt;
&lt;li&gt;Relative Path&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Absolute Path
&lt;/h3&gt;

&lt;p&gt;Absolute path is nothing but a path given from the root of the file system.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/home/user/Desktop/someDirectory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is an example of absolute path because we have to provide the path from the bottom most part of the file system heirarchy.&lt;/p&gt;

&lt;h3&gt;
  
  
  Relative Path
&lt;/h3&gt;

&lt;p&gt;In Relative path we don't have to give whole location of the file. Let's look at the relative path with same example&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Noticed the difference ? The ~ symbol denotes the present working directory (&lt;code&gt;pwd&lt;/code&gt;). If we execute&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;we would get a file path like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/home/user/Desktop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now if I want to navigate to someDirectory folder I can use&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Notice that we haven't used &lt;code&gt;/&lt;/code&gt; which indicates it's a relative directory to present working directory.&lt;/p&gt;

&lt;p&gt;So just keep in mind if you are going to navigate into the files outside of your pwd you have to provide the full path AKA Absolute path otherwise you can use the short path AKA Relative path.&lt;br&gt;
Now its time for a hands on.&lt;/p&gt;
&lt;h2&gt;
  
  
  Examples
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Navigate to Desktop
&lt;/h3&gt;


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

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2EpKUg1E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/klaayyrrmujy6z4lfls9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2EpKUg1E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/klaayyrrmujy6z4lfls9.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's create a file in Desktop with &lt;code&gt;mkdir&lt;/code&gt; command. &lt;br&gt;
&lt;em&gt;[Note : I will write a dedicated blog post for file operation commands in my second blog where i will cover this touch command, for now just know that mkdir command is used to create a empty file in the system].&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir thisFile.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LHz08NA2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aszqfayqejbnwoows8yu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LHz08NA2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aszqfayqejbnwoows8yu.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
Now if you notice the path near the time you will see its a relative path &lt;code&gt;~/Desktop/someDirectory&lt;/code&gt; since we are working in the user space. &lt;/p&gt;
&lt;h3&gt;
  
  
  Navigating back using cd
&lt;/h3&gt;

&lt;p&gt;Now lets say we want to navigate back to the user space from the &lt;code&gt;~/Desktop/someDirectory&lt;/code&gt; folder. we will use cd with two dots i.e &lt;code&gt;cd ..&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;cd ..
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will take us to &lt;code&gt;~/Desktop&lt;/code&gt; folder only. If we want to go further back we can use the same cd ..&lt;br&gt;
&lt;/p&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;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4BTrn9tJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/izds3n6lyeyigqrax284.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4BTrn9tJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/izds3n6lyeyigqrax284.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
But this can be tiring hence we have a shortcut for it. you can concat the dots the number of times you want to go back.&lt;/p&gt;

&lt;p&gt;for example.  We wanted to go to &lt;code&gt;~&lt;/code&gt; from &lt;code&gt;~/Desktop/someDirectory&lt;/code&gt; which means two jumps back so we can use this command&lt;br&gt;
&lt;/p&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;p&gt;This will directly take us to the ~ folder&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ya3aDhvc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/duo7cwowqdx58gfbx9c0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ya3aDhvc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/duo7cwowqdx58gfbx9c0.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
 If there were three jumps then it would be &lt;code&gt;cd ../../../&lt;/code&gt; and similar things for other jumps.&lt;/p&gt;

&lt;p&gt;But wait we can make this even more shorter. If our goal is to reach the ~ folder we can simply use&lt;br&gt;
&lt;/p&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;p&gt;Why does this works ? if you print the &lt;code&gt;~&lt;/code&gt; symbol you will get your user space.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Q0mRsYLD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xuczmctzeuc5uastogkn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Q0mRsYLD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xuczmctzeuc5uastogkn.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;echo&lt;/code&gt; command is similar like print statements in programming languages.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tmTy7qJv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ic8cs78zl2c655gda43f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tmTy7qJv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ic8cs78zl2c655gda43f.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This only works if we want to go to ~ whereas &lt;code&gt;../../&lt;/code&gt; method is more flexible to use and is mostly used when compared with &lt;code&gt;cd ~&lt;/code&gt;.&lt;br&gt;
Now if you are in the user space then you don't have to provide &lt;code&gt;~&lt;/code&gt; with cd i.e to navigate to Desktop folder you can use&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;instead of&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;But what if we want to navigate from a Downloads folder to Desktop/someDirectory ?&lt;br&gt;
Assume that we are already in Downloads folder.&lt;/p&gt;

&lt;p&gt;First Case, we can use&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fezUtoPn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nok3x1noj4qu02lfdhh3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fezUtoPn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nok3x1noj4qu02lfdhh3.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Second Case, here's why we use ~ in front of relative paths. We can achieve the same result using&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--D9T-_Sel--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j9mv2kc3ytrk8khod18v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--D9T-_Sel--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j9mv2kc3ytrk8khod18v.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
Now it might be easy to visualize what &lt;code&gt;~&lt;/code&gt; is right ? As i said earlier it is nothing but &lt;code&gt;/home/user&lt;/code&gt; hence our&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;is actually&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /home/user/Desktop/someDirectory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is why we don't need to use &lt;code&gt;cd ..&lt;/code&gt; like in first case.&lt;/p&gt;

&lt;h3&gt;
  
  
  Navigating in System space
&lt;/h3&gt;

&lt;p&gt;System space is nothing but folders that are used by our system for its own purpose. We will cover this in future.&lt;br&gt;
For now let's keep this simple, anything outside of ~ or &lt;code&gt;/home/user/&lt;/code&gt; is system space.&lt;/p&gt;

&lt;p&gt;There is boot folder in linux which contains all files related to booting the system. To navigate to that folder we have to provide the full path&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6piO-vbI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ajasj50bi4arl06km0wi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6piO-vbI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ajasj50bi4arl06km0wi.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
Noticed something ? The path near the time changed to absolute path &lt;code&gt;/boot&lt;/code&gt;. &lt;br&gt;
This is the only difference between a relative path and absolute path. All the commands discussed for relative paths work similarly in absolute path as well.&lt;/p&gt;

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