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 fornode_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.
A tree is a view, not the filesystem itself
Depth limits, ignored directories, unreadable paths, mount points, and symbolic links all change what appears. Read errors as part of the output, and narrow the view to the question you are asking.
Structure can be sensitive
A directory tree can expose customer names, internal hosts, and private project names without showing file contents. Trim and review it before sharing.
Narrow the view in a large repository
Start with a depth, subtree, or explicit exclusion instead of dumping the entire tree. A smaller view is easier to compare and less likely to expose unrelated names.