Create Graphical View Of Folders In Terminal 4


Create Graphical View Of Folders In Terminal


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.

Where To Next?

  • Subscribe To Mac Tricks And Tips

4 Responses to “Create Graphical View Of Folders In Terminal”

  1. 1

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

    # 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 :

    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

  4. 4


    Comment By on April 11th, at 10:20 pm