#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
└── assets12 directories, 8 files
How to do it
- Install tree
brew install tree - 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/ - Go to any of your projects, and run
tree -L 2. This is will generate a 2 folder-deep tree representation of your project - If you’d like to ignore certain folders (e.g.
node_modulesandbin), use the-Ioption:tree -L 2 -I ‘node_modules|bin' - To copy it on your clipboard, simply add
| pbcopyto the end of your command:tree -L 2 -I ‘node_modules|bin' | pbcopy - tree gives you lots of options to customise your output. Run
tree --helpto see a full list of options.
