This website recently got a major rebuild; if you're missing something, let Lorna know.

The Tree Command



Today I'm working on a little tutorial (about writing RESTful services, for this site) and I used the tree command to illustrate the file and directory layout of the project. I love this little command and use it frequently, but it isn't very well known so here's a quick example.

As with most linux command line utilities, it does only one thing and it does it very well. In this case, it shows the file structure. For my work-in-progress project (which handily only has a few files so has fairly short output), it does this:

$ tree .
.
├── controllers
│   ├── MyController.php
│   └── UsersController.php
├── index.php
├── models
└── views

3 directories, 3 files

The . that was passed here is the name of the directory to generate the tree for; the dot means to use the current directory. You can also pass switches limiting the depth of the listing, showing full paths to each file or directory, and omitting the indentations - as well as a large number of other options that seem less useful!

I use the tree command to put into blog posts, talk slides, and so on - I think it's clear and easy to read (especially because the toolchain I'm using for slides at the moment make most screenshots look decidedly chewed!), and also just to remind myself where all the various pieces of a project can be found.


In: tech
Tags: #cli #linux #tree