Luke Oliff.

TIL: Visualising Directory Structures With tree

·TIL·1 min read·Luke Oliff

A directory tree tells you in two seconds what someone spent two weeks building. tree prints that.

tree src/

Output shows every directory and file nested with indentation and connecting lines.

tree -L 2 src/

Limit the depth to 2 levels. Deep directory structures produce too much output. The -L flag keeps it readable.

tree -I 'node_modules|.git|dist' --dirsfirst

The -I flag excludes patterns. –dirsfirst shows directories before files. The combination gives a clean view of just your source code.

tree -J src/

JSON output format. Parse it with jq for automated documentation generation.

Is tree on macOS?

brew install tree