15

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

2 Answers 2

17

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

0
1

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
1
  • 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, 2015 at 17:54

You must log in to answer this question.

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