Sitemap

#TodayILearned: How to generate a tree representation of your project

2 min readMar 2, 2017

For some time now, I’ve been wanting to write a series of short and simple articles documenting the things I’ve learnt. The idea is to share the smallest unit of information that can be useful and valuable to the “me” yesterday (or you, if you were in the same state as yesterday’s me on a given topic).

Enjoy!

Yesterday, I learnt a cool and simple way to generate a tree representation of your project folder structure.

Here’s an example:

.
├── Gemfile
├── Gemfile.lock
├── README.md
├── Rakefile
├── app
│ ├── assets
│ ├── controllers
│ ├── helpers
│ ├── mailers
│ ├── models
│ └── views
├── config.ru
├── package.json
├── spec
│ ├── features
│ ├── javascripts
│ ├── rails_helper.rb
│ └── spec_helper.rb
└── vendor
└── assets
12 directories, 8 files

How to do it

  1. Install tree brew install tree
  2. If you see an error that says brew: command not found , it means that you haven’t installed homebrew. It’s a great package manager for macOS, and it’s widely used. You can install it by running the first command listed on https://brew.sh/
  3. Go to any of your projects, and run tree -L 2. This is will generate a 2 folder-deep tree representation of your project
  4. If you’d like to ignore certain folders (e.g. node_modules and bin), use the -I option: tree -L 2 -I ‘node_modules|bin'
  5. To copy it on your clipboard, simply add | pbcopy to the end of your command: tree -L 2 -I ‘node_modules|bin' | pbcopy
  6. tree gives you lots of options to customise your output. Run tree --help to see a full list of options.

--

--

David
David

Written by David

Author of Effective ML Teams (O'Reilly)

No responses yet