The Tree Command
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.
Hi Lorna
You *blow me away* with these tips! I’d never heard of this command so I couldn’t wait to give it a try. It doesn’t work on a Mac by default, but I quickly found this blog post with some super easy instructions on how to install and get it working: http://shaunchapmanblog.com/post/329270449/how-to-install-the-tree-command-on-mac-os-x
I’ll definitely use this command a lot going forward. Thanks!
Tocacar
This is very useful tip for describing files and directories . I ve never heard of it .
Thanks,
I have a *bunch* of these posts on this site – I even give a talk along these lines too, for more neat tricks have a look at it: http://www.slideshare.net/lornajane/linuxfu-for-php-developers
This is a really useful command to have in your toolbox.
For Debian based Linux distros you can easily install it using Apt:
$ sudo aptitude install tree
FYI you can save two key strokes by just typing ‘tree’. ;) This will default to your current directory.
Also if your directory structure is very deep and you’re just interested in the immediate depth you can pass the -L parameter to limit how deep tree recurses:
$ tree -L 2
Nice tool, can be quickly installed using “yum install tree” on centos / fedora etc.
One point to note, when using a putty shell you can use the -A switch to print ANSI indentation lines. Otherwise you could end up with a bunch of unreadable junk, like so…
“â  â  â  âââ prev-horizontal.png”
(also -S prints ASCII)
I think you would have a lot less hassle configuring PuTTY to accept the proper character set instead. Change Settings -> Window -> Translation -> UTF-8.
Hi,
If you use Ubuntu, you can fix with that commande :
$>alias tree=’tree –charset=ASCII’
Cheers,