{"id":10501,"date":"2015-05-17T22:15:29","date_gmt":"2015-05-17T22:15:29","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=10501"},"modified":"2015-05-17T22:15:29","modified_gmt":"2015-05-17T22:15:29","slug":"linux-terminal-listing-subdirectories-directories-only","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/linux-terminal-listing-subdirectories-directories-only\/","title":{"rendered":"Linux:  terminal:  listing subdirectories (directories) only"},"content":{"rendered":"<h1>The tutor shares a nice tip that he finds very helpful:\u00a0 listing the subdirectories only with the <em>ls<\/em> command.<\/h1>\n<p>I write a lot of little programs to test built-in functions or show examples of their use.\u00a0 Of course, as they accumulate, organizing them becomes important.<\/p>\n<p>Before reading further, an important relationship to keep in mind is that a directory is to the terminal what a folder is to the desktop.  A subdirectory, then, is like a folder within a folder. I use both file environments, so I use the terms directory and folder interchangeably.<\/p>\n<p>Very often, I&#8217;ll store a day&#8217;s work in a folder labeled that date, within another folder for the project to which it belongs or what have you.\u00a0 Returning weeks later, I need to know, from an upper directory, where the folder (aka subdirectory) of a particular date might be.<\/p>\n<p>While there are several ways to find out, I like <span style=\"font-family:monospace;color:olive\">ls<\/span> because it&#8217;s quick and minimal -especially if you know how to tailor it.  The good people at <a href=\"http:\/\/stackoverflow.com\/questions\/14352290\/listing-only-directory-using-ls-in-bash\">stackoverflow.com<\/a> offer the variation<\/p>\n<p><span style=\"font-family:monospace;color:olive\">ls -d *\/<\/span><\/p>\n<p>as the way to return the subdirectories only.<\/p>\n<p>But what if you want (like me) to know how deep the structure goes?<\/p>\n<p>You can check for second-level subdirectories thus:<\/p>\n<p><span style=\"font-family:monospace;color:olive\">ls -d *\/*\/<\/span><\/p>\n<p>or third-level thus:<\/p>\n<p><span style=\"font-family:monospace;color:olive\">ls -d *\/*\/*\/<\/p>\n<p>You can also do simultaneous checks:<\/p>\n<p><span style=\"font-family:monospace;color:olive\">ls -d *\/ *\/*\/<\/p>\n<p>reveals the subdirectories in the current one, as well as the ones they contain.<\/p>\n<p>There might be better ways to search around, but for my purposes these variations of <span style=\"font-family:monospace;color:olive\">ls<\/span> work great.<\/p>\n<p>HTH:)<\/p>\n<p>Jack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The tutor shares a nice tip that he finds very helpful:\u00a0 listing the subdirectories only with the ls command. I write a lot of little programs to test built-in functions or show examples of their use.\u00a0 Of course, as they &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/linux-terminal-listing-subdirectories-directories-only\/\"> <span class=\"screen-reader-text\">Linux:  terminal:  listing subdirectories (directories) only<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105,637],"tags":[808,809,807,810,806],"class_list":["post-10501","post","type-post","status-publish","format-standard","hentry","category-computer-science","category-linux","tag-listing-directories-only","tag-listing-subdirectories-only","tag-ls","tag-ls-d","tag-terminal-commands"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/10501","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/comments?post=10501"}],"version-history":[{"count":22,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/10501\/revisions"}],"predecessor-version":[{"id":10523,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/10501\/revisions\/10523"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=10501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=10501"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=10501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}