Showing posts with label ls. Show all posts
Showing posts with label ls. Show all posts

Wednesday, October 24, 2012

[COMMAND LINE] Display structure of directory hierarchy

Let's say you're working on the terminal and want to display current's directory hierarchy in a tree structure, like this:

$ tree.sh .kde/share/apps/krita/

/home/wilson/.kde/share/apps/krita
   .
   |-paintoppresets
   |-templates
   |---CMYK
   |---Ink
   |---WS
   |-workspaces

I found the command below on the web and its author even provided it as a shell script to use it easily.

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

Install system wide

Open a terminal window and run:

dst="/usr/local/bin/tree.sh" && sudo wget http://goo.gl/z8exN -O $dst && sudo chmod +x $dst

Install for current user

This will install the script for your user only and assumes you have a bin directory on your home directory and it has been added to $PATH. Open a terminal window and run:

dst="$HOME/bin/tree.sh" && wget http://goo.gl/z8exN -O $dst && chmod +x $dst

References

Unix Tree / Linux Tree - Display Structure of Directory Hierarchy