{"id":665,"date":"2022-02-16T16:11:57","date_gmt":"2022-02-16T21:11:57","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=665"},"modified":"2022-02-16T16:11:59","modified_gmt":"2022-02-16T21:11:59","slug":"using-ls-to-display-a-file-tree","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/using-ls-to-display-a-file-tree\/","title":{"rendered":"Using ls to display a file tree"},"content":{"rendered":"\n<p>Recently, I found a really elegant solution to display a file tree using the ls command. I like is so much that I feel the need to share it. The code is:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>ls -R | grep &#8220;:$&#8221; | sed -e &#8216;s\/:$\/\/&#8217; -e &#8216;s\/[^-][^\\\/]*\\\/\/&#8211;\/g&#8217; -e &#8216;s\/^\/ \/&#8217; -e &#8216;s\/-\/|\/&#8217;<\/p><\/blockquote>\n\n\n\n<p>It displays files as follows:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>.<br>|-application<br>|&#8212;configs<br>|&#8212;controllers<br>|&#8212;models<br>|&#8212;views<br>|&#8212;&#8211;helpers<br>|&#8212;&#8211;scripts<br>|&#8212;&#8212;-error<br>|&#8212;&#8212;-index<br>|-docs<br>|-library<br>|-public<br>|-tests<br>|&#8212;application<br>|&#8212;library<\/p><\/blockquote>\n\n\n\n<p>I got this code from <a href=\"http:\/\/www.centerkey.com\/tree\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/www.centerkey.com\/tree<\/a> and you will also find a ready to go shell script there.<\/p>\n\n\n\n<p>If you want to add this your bashrc to create an alias, you would run into your problem since bash doesn&#8217;t allow single quotes inside inside single quotes even if they are escaped with backslash.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently, I found a really elegant solution to display a file tree using the ls command. I like is so much that I feel the need to share it. The code is: ls -R | grep &#8220;:$&#8221; | sed -e &#8216;s\/:$\/\/&#8217; -e &#8216;s\/[^-][^\\\/]*\\\/\/&#8211;\/g&#8217; -e &#8216;s\/^\/ \/&#8217; -e &#8216;s\/-\/|\/&#8217; It displays files as follows: .|-application|&#8212;configs|&#8212;controllers|&#8212;models|&#8212;views|&#8212;&#8211;helpers|&#8212;&#8211;scripts|&#8212;&#8212;-error|&#8212;&#8212;-index|-docs|-library|-public|-tests|&#8212;application|&#8212;library I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101,34],"tags":[94,35],"class_list":["post-665","post","type-post","status-publish","format-standard","hentry","category-bash","category-linux","tag-bash","tag-linux"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/665","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/comments?post=665"}],"version-history":[{"count":1,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/665\/revisions"}],"predecessor-version":[{"id":667,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/665\/revisions\/667"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=665"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=665"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=665"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}