tree
Overview
tree prints a directory hierarchy as an indented tree. It is excellent for quick structural overviews, documentation screenshots, and seeing project layout without a full recursive ls. Often an optional package (sudo apt install tree / dnf install tree).
For huge trees, limit depth (-L) and prune noisy dirs (-I). For size-oriented exploration, prefer du, dust, duf, or ncdu.
Syntax
tree [options] [directory ...]Common Options
| Option | Description |
|---|---|
-L n |
Max depth |
-a |
Include hidden files |
-d |
Directories only |
-f |
Print full path prefix for each entry |
-i |
No indentation lines (plain list with nesting) |
-h |
Human-readable sizes (with size options) |
-s |
Raw sizes |
--du |
Report directory sizes (when supported) |
-P pattern |
Include only matching files |
-I pattern |
Exclude pattern (often |-separated) |
-C / -n |
Color on / off |
-H url |
HTML output with base URL |
-J / -X |
JSON / XML (newer tree) |
--gitignore |
Honor .gitignore (newer tree) |
-p / -u / -g |
Permissions / user / group |
-D |
Show modified time |
--dirsfirst |
List directories before files |
Examples with Explanations
Shallow overview
tree -L 2
tree -L 3 /etc
tree -d -L 3 /etc/systemdHide dependency / VCS noise
tree -I 'node_modules|.git|dist|target|.venv|__pycache__'
tree -L 2 -I 'node_modules|.git'Sizes
tree -h -L 2 --du # if your tree supports --du
tree -h -L 1 /varFull paths and filtering
tree -f -L 2
tree -P '*.service' -L 3 /etc/systemd
tree -P '*.md' -I node_modulesHTML report
tree -H '.' -L 2 -o /tmp/tree.html
# open /tmp/tree.html in a browserJSON for tooling (when available)
tree -J -L 2 > tree.jsonCompare with find / eza
tree -L 2
find . -maxdepth 2
eza -T -L 2 # modern ls alternative with tree modeDocument a project layout
tree -L 2 -I '.git|node_modules' > STRUCTURE.txtNotes / Pitfalls
- Not installed by default on many minimal servers — package name is usually
tree. - Unbounded
treeon/or large NFS shares is slow and noisy; always use-L/-I. - Patterns for
-P/-Iare not full shell globs in all versions; checkman tree. - Color codes can break logs; use
-nor redirect carefully. - Do not treat
treeas a security audit tool; it follows normal user permissions and may hide unreadable dirs.
2026-relevant notes
- Prefer
eza -Torlsd --treeif you already use modernlsreplacements; keep classictreefor portable docs. --gitignoresupport varies; upgradetreeor combine withfdfor git-aware listing.- In monorepos, generate shallow trees for READMEs rather than committing giant dumps.
Additional Resources
man tree