07
Feb
08
Tagged Under: , ,
Create Graphical View Of Folders In Terminal

Hey

This is a rather cool unix/linux trick that is used to create a graphical representation of the current sub-directories in the current folder. For example you get a a cool text view of all of the folders within Terminal. For example if you look at the image below you should get a better idea of what I am on about.


Its simple to do and is rather cool.

Open up Terminal from Utilities, and change the directory to something that doesn’t have to many sub folders. You could do this on your root folder but you would be here for every as it maps every single folder and sub folder etc. To change the folder you are in within Terminal type something similar to the following, you will have to change it based on what you have installed on your computer.

cd /Users/James/Stuff

This should change the folder to something more manageable for this quick demo. Then copy and paste the following line.

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//–/g’ -e ’s/^/ /’ -e ’s/-/|/’

This opens and runs a small program called tree, it analyzes the folders and sub-folders and graphs them on screen.

Pretty cool if you use Terminal a lot. I don’t so it isn’t that much use to me.

If you want to keep up with the latests post from Mac Tricks And Tips I recommend you subscribe to the RSS Feed. To find out more about RSS check out the help page form more information.

Save/Promote This Post

If you enjoyed reading this article, post you vote. Each vote is highly appreciated. Find out more about bookmarking here

3 Responses


  1. 1

    If you want to make the tree function simpler, you can copy this into a plain text file called tree:

    #!/bin/bash
    # tree
    ls -R | grep “:$” | sed -e ’s/:$//’ -e ’s/[^-][^\/]*\//–/g’ -e ’s/^/ /’ -e ’s/-/|/’

    and save it in /bin. You can’t find /bin in Finder, so you have to use this command:

    sudo cp ./tree /bin/tree

    to move it there. Then, you have to make it runnable:

    chmod 755 /bin/tree

    From then on, anytime you just type “tree” into Terminal, it will give you a tree view for the active directory.

    Comment By themuffinking on February 8th, at 9:00 pm
  2. 2

    Thanks a lot themuffinking thats a great comment. I don’t no a great deal about all the commands. Thanks

    Comment By James Powell on February 8th, at 9:30 pm
  3. 3

    @themuffinking : even better, add argument parsing like this :

    #!/bin/bash
    echo ‘Listing of’ $1
    ls -R $1 | grep “:$” | sed -e ’s/:$//’ -e ’s/[^-][^\/]*\//–/g’ -e ’s/^/ /’ -e ’s/-/|/’

    That way, you don’t have to “cd” to the directory you want to list. Just type “tree /etc”, for example.

    Comment By TZ on February 10th, at 8:25 am

Trackbacks/Pingbacks (Trackback URL)

Please use the Trackback URL above to get properly credited

Respond

Name (required)

Mail (will not be published) (required)

Website

Comments Guidelines

  • Only basic HTML tags are allowed:
  • <a href> <h1 - h6> <acronym> <code> <em> <strike> <strong> <i> <b>
  • Spam comments will be deleted and IP's and websites blacklisted.
  • Remember the rules are here to make sure every one has a good time.
  • If you want more information visit the Comment Guidelines & Help page.

Live Comment Preview:

1,847 Spam comments caught. So why bother spamming?

Small RSS Icon