C.W.K.
Stream
Lesson 11 of 12 · published

tree — Visualizing Directories

~8 min · tree, visualization

Level 0Window Tourist
0 XP0/95 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

What ls -R wishes it was

ls -R lists a tree but it's hard to read. tree draws ASCII branches that show structure at a glance. Install with brew install tree on macOS; most Linux distros ship it.

The flags you'll actually use

  • -L 2 — limit depth to 2. Without it, large repos explode.
  • -d — directories only.
  • -a — show hidden.
  • -h — human-readable sizes (with -s or --du).
  • -I 'pattern|other' — ignore matching names. Crucial for node_modules, .git, __pycache__.
  • --gitignore — respect .gitignore files automatically.

Output formats

tree -J emits JSON. tree -X emits XML. Useful when you want to feed structure to a script or a documentation generator.

Why it matters in practice

When you're explaining a project to a teammate, paste a tree -L 2 -I 'node_modules|.git' output into Slack or a README. Three lines tell more than a paragraph.

Code

Sane defaults for project trees·bash
brew install tree   # macOS
tree -L 2 -I 'node_modules|.git|__pycache__' .
# Pretty + sizes
tree -L 3 -h --du -I 'node_modules|.git'

External links

Exercise

Install tree (brew install tree). Run tree -L 2 -I 'node_modules|.git' ~/projects (or wherever your code lives). Compare to plain ls -R. Add a tree alias to your .zshrc.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.