{"id":430,"date":"2024-01-12T18:27:45","date_gmt":"2024-01-13T00:27:45","guid":{"rendered":"https:\/\/techlensfocus.com\/?p=430"},"modified":"2024-06-17T19:51:54","modified_gmt":"2024-06-18T00:51:54","slug":"mastering-linux-how-to-traverse-directories-using-the-cd-command","status":"publish","type":"post","link":"https:\/\/techlensfocus.com\/index.php\/2024\/01\/12\/mastering-linux-how-to-traverse-directories-using-the-cd-command\/","title":{"rendered":"Mastering Linux: How to Traverse Directories using the \u2018cd\u2019 Command"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<div class=\"wp-block-ideabox-toc ib-block-toc\" data-anchors='h2,h3,h4,h5,h6' data-collapsable='true' ><div class=\"ib-toc-container ib-toc-list-style-numbers ib-toc-hierarchical ib-toc-expanded\"><div class=\"ib-toc-header\"><div class=\"ib-toc-header-title\">Table of Contents<\/div><div class=\"ib-toc-header-right\"><span class=\"ib-toc-icon-collapse\"><span class=\"dashicon dashicons dashicons-minus\"><\/span><\/span><span class=\"ib-toc-icon-expand\"><span class=\"dashicon dashicons dashicons-plus\"><\/span><\/span><\/div><\/div><div class=\"ib-toc-separator\" style=\"height:2px\"><\/div><div class=\"ib-toc-body\"><ol class=\"ib-toc-anchors\"><\/ol><\/div><\/div><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>The &#8216;<strong>cd<\/strong>&#8216; command in Linux stands for &#8220;change directory.&#8221; It is a command used to navigate through the file system by switching between directories. By entering &#8220;cd&#8221; followed by the name of the directory, you can move from one location to another within the Linux file structure. Additionally, using certain options with &#8216;<strong>cd<\/strong>&#8216; allows for more advanced navigation, such as moving to the home directory or the previous directory. Mastering the &#8216;cd&#8217; command is essential for any Linux user.<\/p>\n\n\n\n<p>You can <a href=\"https:\/\/techlensfocus.com\/index.php\/2024\/01\/12\/understanding-linux-filesystem-and-the-directory-structure\/\" target=\"_blank\" rel=\"noopener\" title=\"\">click here<\/a> to learn more about Linux Filesystem and Directory Structure before dive into <strong>cd<\/strong> command. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Absolute directory references<\/h2>\n\n\n\n<p>Using absolute directory references means providing a complete path from the root directory to a specific directory or file. In the context of the &#8216;cd&#8217; command, this involves specifying the entire path starting from the root directory (&#8220;<strong>\/<\/strong>&#8220;). <\/p>\n\n\n\n<p>For instance, if you want to change to the &#8220;Documents&#8221; directory within the &#8220;user&#8221; directory, you would use the absolute path like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"93\" src=\"https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-4.58.01\u202fPM-1024x93.png\" alt=\"\" class=\"wp-image-440\" srcset=\"https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-4.58.01\u202fPM-1024x93.png 1024w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-4.58.01\u202fPM-300x27.png 300w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-4.58.01\u202fPM-768x70.png 768w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-4.58.01\u202fPM-1280x118.png 1280w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-4.58.01\u202fPM.png 1296w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>To be more clear, you can display the location via shell command. Use the <strong>pwd<\/strong> command. This command displays the absolute path of the current working directory. It is useful to determine your current location within the file system. pwd stands for &#8220;print working directory.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"114\" src=\"https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.05.29\u202fPM-1024x114.png\" alt=\"\" class=\"wp-image-444\" srcset=\"https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.05.29\u202fPM-1024x114.png 1024w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.05.29\u202fPM-300x33.png 300w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.05.29\u202fPM-768x85.png 768w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.05.29\u202fPM-1280x144.png 1280w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.05.29\u202fPM.png 1294w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Let&#8217;s do another example: we will changes the current working directory to &#8220;<strong>\/home\/tim\/Templates<\/strong>&#8221; It means you&#8217;re navigating to the &#8220;Templates&#8221; directory inside the &#8220;tim&#8221; user&#8217;s home directory. After that, running &#8216;<strong>pwd<\/strong>&#8216; will print the current working directory.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"114\" src=\"https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.09.45\u202fPM-1024x114.png\" alt=\"\" class=\"wp-image-447\" srcset=\"https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.09.45\u202fPM-1024x114.png 1024w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.09.45\u202fPM-300x33.png 300w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.09.45\u202fPM-768x85.png 768w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.09.45\u202fPM-1280x144.png 1280w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.09.45\u202fPM.png 1294w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Relative directory references<\/h2>\n\n\n\n<p>Relative directory references in Linux involve specifying the path to a directory relative to the current working directory. Instead of providing the complete path from the root directory (&#8220;\/&#8221;), you indicate the path starting from your current location in the file system.<\/p>\n\n\n\n<p>For example, if your current working directory is &#8220;<strong>\/home\/tim\/<\/strong>&#8221; and you want to navigate to the &#8220;Documents&#8221; directory, which is a subdirectory of your current location, you can just do like this <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"71\" src=\"https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.37.59\u202fPM-1024x71.png\" alt=\"\" class=\"wp-image-456\" srcset=\"https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.37.59\u202fPM-1024x71.png 1024w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.37.59\u202fPM-300x21.png 300w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.37.59\u202fPM-768x53.png 768w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.37.59\u202fPM-1280x90.png 1280w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.37.59\u202fPM.png 1294w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Here is a tip for you :<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use single dot (<strong>.<\/strong>) to refer the current directory<\/li>\n\n\n\n<li>use double dot (<strong>..<\/strong>) to refer to the parent directory<\/li>\n<\/ul>\n\n\n\n<p>In this example, if you are in &#8220;<strong>\/home\/tim\/Documents&#8221;<\/strong> and you want to refer to the current directory, you can use: <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"71\" src=\"https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.54.23\u202fPM-1024x71.png\" alt=\"\" class=\"wp-image-460\" srcset=\"https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.54.23\u202fPM-1024x71.png 1024w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.54.23\u202fPM-300x21.png 300w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.54.23\u202fPM-768x53.png 768w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.54.23\u202fPM-1280x90.png 1280w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.54.23\u202fPM.png 1294w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>This example using double dot. If you are in &#8220;<strong>\/home\/tim\/Documents<\/strong>&#8221; and you want to move up one level to &#8220;<strong>\/home\/tim<\/strong>,&#8221; you can use<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"111\" src=\"https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.56.30\u202fPM-1024x111.png\" alt=\"\" class=\"wp-image-461\" srcset=\"https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.56.30\u202fPM-1024x111.png 1024w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.56.30\u202fPM-300x32.png 300w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.56.30\u202fPM-768x83.png 768w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.56.30\u202fPM-1280x140.png 1280w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-5.56.30\u202fPM.png 1294w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Note that use can use either <strong>cd .. <\/strong>or <strong>cd ..\/ <\/strong><\/p>\n\n\n\n<p>Use can also go to two level up, use .<strong>.\/..\/ <\/strong>refers the parent of the parent directory, see example below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"111\" src=\"https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-6.00.33\u202fPM-1024x111.png\" alt=\"\" class=\"wp-image-464\" srcset=\"https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-6.00.33\u202fPM-1024x111.png 1024w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-6.00.33\u202fPM-300x32.png 300w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-6.00.33\u202fPM-768x83.png 768w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-6.00.33\u202fPM-1280x140.png 1280w, https:\/\/techlensfocus.com\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-12-at-6.00.33\u202fPM.png 1294w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The example use <strong>cd ..\/..\/<\/strong> to moved up two levels in the directory structure, transitioning from &#8220;\/<strong>home\/tim\/Test1\/SubFolder 3<\/strong>&#8221; to &#8220;<strong>\/home\/tim<\/strong>&#8220;<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<p>In conclusion, mastering the &#8216;<strong>cd<\/strong>&#8216; command in Linux opens a gateway to seamless directory navigation. Whether using absolute paths or relative path, choosing the appropriate method based on the task at hand is crucial for effective directory navigation. Also, it is a good habit to use <strong>pwd<\/strong> command to verify your current location.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">More Resources<\/h2>\n\n\n\n<p><a href=\"https:\/\/www.geeksforgeeks.org\/cd-command-in-linux-with-examples\/\" target=\"_blank\" rel=\"noopener\" title=\"\">How to Change the Directory in Linux | cd Command<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/www.linuxteck.com\/cd-command-tips-in-linux\/\" target=\"_blank\" rel=\"noopener\" title=\"\">10 Useful cd command tips in Linux<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Key techniques in navigating directories with precision using the powerful &#8216;cd&#8217; command. <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[6,16],"tags":[38,66,39],"class_list":["post-430","post","type-post","status-publish","format-standard","hentry","category-it","category-linux","tag-cd-command","tag-linux-command","tag-traverse-directories"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/techlensfocus.com\/index.php\/wp-json\/wp\/v2\/posts\/430","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techlensfocus.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techlensfocus.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techlensfocus.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techlensfocus.com\/index.php\/wp-json\/wp\/v2\/comments?post=430"}],"version-history":[{"count":34,"href":"https:\/\/techlensfocus.com\/index.php\/wp-json\/wp\/v2\/posts\/430\/revisions"}],"predecessor-version":[{"id":474,"href":"https:\/\/techlensfocus.com\/index.php\/wp-json\/wp\/v2\/posts\/430\/revisions\/474"}],"wp:attachment":[{"href":"https:\/\/techlensfocus.com\/index.php\/wp-json\/wp\/v2\/media?parent=430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techlensfocus.com\/index.php\/wp-json\/wp\/v2\/categories?post=430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techlensfocus.com\/index.php\/wp-json\/wp\/v2\/tags?post=430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}