{"id":29700,"date":"2022-04-24T04:38:48","date_gmt":"2022-04-24T04:38:48","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=29700"},"modified":"2022-12-23T06:19:29","modified_gmt":"2022-12-23T06:19:29","slug":"linux-tutorials-understanding-absolute-and-relative-path","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/linux-tutorials-understanding-absolute-and-relative-path\/","title":{"rendered":"Linux Tutorials: Understanding absolute and relative path"},"content":{"rendered":"\n<p>When specifying a directory to change to, you can use either absolute or relative path names. The absolute or full path starts from the system root \/, and the relative path starts from your current directory.<\/p>\n\n\n\n<p>By default, when you log into your Linux system, your current working directory is set to your home directory. Assuming that the Downloads directory exists in your home directory, you can navigate to it by using the relative path to the directory:<\/p>\n\n\n\n<p>$ cd Downloads<\/p>\n\n\n\n<p>You can also navigate to the same directory by using its absolute path:<\/p>\n\n\n\n<p>$ cd \/home\/username\/Downloads<\/p>\n\n\n\n<p>In short, if the path starts with a slash (\/), it is the absolute path to the directory<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/04\/linux-tutorial-absolute-relative-1-1024x576.jpg\" alt=\"\" class=\"wp-image-29701\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/04\/linux-tutorial-absolute-relative-1-1024x576.jpg 1024w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/04\/linux-tutorial-absolute-relative-1-300x169.jpg 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/04\/linux-tutorial-absolute-relative-1-768x432.jpg 768w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/04\/linux-tutorial-absolute-relative-1-355x199.jpg 355w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/04\/linux-tutorial-absolute-relative-1.jpg 1280w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"650\" height=\"330\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/04\/linux-tutorial-absolute-relative-2.jpg\" alt=\"\" class=\"wp-image-29702\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/04\/linux-tutorial-absolute-relative-2.jpg 650w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/04\/linux-tutorial-absolute-relative-2-300x152.jpg 300w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"458\" height=\"168\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/04\/linux-tutorial-absolute-relative-3.png\" alt=\"\" class=\"wp-image-29703\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/04\/linux-tutorial-absolute-relative-3.png 458w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/04\/linux-tutorial-absolute-relative-3-300x110.png 300w\" sizes=\"auto, (max-width: 458px) 100vw, 458px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"638\" height=\"479\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/04\/linux-tutorial-absolute-relative-4.jpeg\" alt=\"\" class=\"wp-image-29704\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/04\/linux-tutorial-absolute-relative-4.jpeg 638w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/04\/linux-tutorial-absolute-relative-4-300x225.jpeg 300w\" sizes=\"auto, (max-width: 638px) 100vw, 638px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Linux: Absolute Path<\/strong><\/h2>\n\n\n\n<p>$ cd&nbsp;<strong>\/usr\/lib<\/strong>$ cd&nbsp;<strong>\/usr\/lib pwd<\/strong><br>See this path (<strong>linux#1\/usr\/lib<\/strong>), when you give PWD, it gives a full path from the root level. This is called absolute or full path.<\/p>\n\n\n\n<p>Think of the absolute pathname as being the complete mailing address for a package that the postal service will deliver to your next-door neighbor.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Linux: Relative Path<\/h2>\n\n\n\n<p>$ cd&nbsp;<strong>usr<\/strong>$ \/user&nbsp;<strong>cd lib<\/strong>$ \/usr\/lib&nbsp;<strong>pwd<\/strong>$ linux#1\/usr\/lib&nbsp; &nbsp; ==&gt; Going step by step and achieving.<br>$ linux#1\/usr\/lib&nbsp; cd ..\/..\/&nbsp; &nbsp;==&gt; This is the method of going back step by step.<br>$ linux#1&nbsp; ==&gt; This is root level directory<br>You are currently in the&nbsp;<strong>lib<\/strong>&nbsp;directory. So relative path nothing but complete information of all the mother directories.<br>Here, for&nbsp;<strong>lib<\/strong>, the&nbsp;<strong>usr<\/strong>&nbsp;is the mother directory.<br>In simple terms, it is a step-by-step way and to reach your target directory.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When specifying a directory to change to, you can use either absolute or relative path names. The absolute or full path starts from the system root \/, and the relative&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[2],"tags":[],"class_list":["post-29700","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/29700","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=29700"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/29700\/revisions"}],"predecessor-version":[{"id":29705,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/29700\/revisions\/29705"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=29700"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=29700"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=29700"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}