Visualizing Directory Structures with the Tree Command

Sometimes good old ls just doesn’t cut it when you’re browsing directories from the command line. Sometimes you just need a more visual overview of the nested files and directories. Well, it turns out there’s a useful command for those cases, and it’s available for Linux, OS X, FreeBSD and just about any OS you can think of. (Except Windows, of course.) It’s called tree.

To install it on OS X, with Homebrew:

brew install tree

On Ubuntu/Debian, or other Linux distros that use Debian packages:

apt-get install tree

To use it, just navigate to a directory and type tree. It has various options (visible with tree --help), so you can limit how many levels down it will go, exclude items that match a pattern, adjust sorting, etc.. You get a spiffy diagram that looks something like this:

.
├── application.rb
├── boot.rb
├── database.yml
├── environment.rb
├── environments
│   ├── development.rb
│   ├── production.rb
│   └── test.rb
├── initializers
│   ├── backtrace_silencers.rb
│   ├── filter_parameter_logging.rb
│   ├── inflections.rb
│   ├── mime_types.rb
│   ├── secret_token.rb
│   ├── session_store.rb
│   └── wrap_parameters.rb
├── locales
│   └── en.yml
└── routes.rb

Is that cool or what? This should be quite useful for writing tutorials, since a plain-text directory tree is more accessible than a screenshot of a file manager window.

  • nadjetey

    Isn’t tree originally a Microsoft DOS (Windows) command? http://www.computerhope.com/treehlp.htm

  • Manish Mandal

    Yes tree was there in MS-DOS and is there in Windows too.

  • FredLuis

    Thanks for supporting the idea of 360 degree feedback. I’ve seen it create division in senior teams when handled incorrectly and seen transformation happen when used elegantly. It’s all about the intention and skill of those who facilitate the process. tree care

  • Angie Lyn

    Great, it turns out there’s a useful command for those cases. Gutter Company Lehigh Valley

  • Rosa Mannelli

    This should be more useful for writing tutorials.
    https://www.arlingtondrywallpros.com/drywall-hole-repair-arlington-texas-usa

  • Jack Briggs

    Glad I was able to read this article! Thanks for this. – Matt

  • Adele Adkins

    This is such a complicated topic but the way you explained it in this article made it really easy to comprehend. free consultation

  • Jack Selleck

    One additional visible change with respect to mechanisms defined in relates to Depth -a new data type that describes the maximum depth of tree-printing. Concrete Contractors Near Me

  • Naoma Laopa

    For those situations, it turns out there’s a helpful command that works with Linux, OS X, FreeBSD, and pretty much any other OS you can think of. | fencing timber christchurch

  • Naoma Laopa

    There are moments when all you need is a more graphic summary of the nested folders and files. http://hamiltondemolition.co.nz