Thursday, February 07, 2008

Tree view in UNIX

I found this is interesting. If you like to get your directory structure in a tree view with a single command try following.

  1. Create a shell script in directory /usr/local/bin/ (You need root permission)
  2. Give it a name (I call it gr. )
  3. Edit the script (usr/local/bin/gr)to include following command using a suitable editor (such as vi ;-))

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

  4. Give excutable rights
    % chmod +x /usr/local/bin/gr

  5. Now go to any directory, (My preferred is Apache Rampart/C source) and issue
    % gr

    That should give you a tree view as follows.
       .
    |-core
    |-data
    |-handlers
    |-omxmlsec
    |---c14n
    |---openssl
    |---saml
    |---tokens
    |-secconv
    |-trust
    |-util



1 comment:

Lahiru Sandakith Gallege said...

This will do I guess,

apt-get install tree

man tree

TREE(1) TREE(1)

NAME
tree - list contents of directories in a tree-like format.