Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can you pretty print a directory structure with all subdirectories to the deepest level in the linux terminal(ubuntu)? This is an example of such a pretty print output for a mysite folder:

mysite
|-- manage.py
|-- mysite
    |-- __init__.py
    |-- settings.py
    |-- urls.py
    |-- wsgi.py
|-- polls
    |-- __init__.py
    |-- models.py
    |-- tests.py
    |-- views.py
    |-- static
        |-- css
            |-- styles.css
|-- templates
    |-- polls
        |-- index.html
share|improve this question
up vote 11 down vote accepted

You can use the tree command. You might need to install it if it is not already installed.

share|improve this answer
    
Awesome, thanks!!! – Bentley4 Jul 23 '12 at 11:56

A shell only version, usage: dirtree

DIR=${1:-`pwd`}
SPACING=${2:-|} 
cd $DIR 
for x in * ; do
  [ -d $DIR/$x ] && echo "$SPACING\`-{"$x && $0 $DIR/$x "$SPACING "
done
share|improve this answer
    
Hard to follow this, and hard to use. It doesn’t want to run for me. (I’m not on ubuntu though, but this looks portable enough.) What do you mean, usage: dirtree? – Alan H. Aug 6 '15 at 17:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .