You type tree in the Terminal and get zsh: command not found: tree. Nothing is wrong with your Mac — tree has never been part of macOS. It is a GPL utility from the Linux world, and Apple does not ship it. There are three ways forward: install it, or use one of two things macOS does have.
Confirm it really is missing
Before assuming a broken PATH, check whether the file exists at all. macOS keeps its own command-line tools in three directories, and tree is in none of them:
$ ls /usr/bin/tree /bin/tree /usr/sbin/tree
ls: /bin/tree: No such file or directory
ls: /usr/bin/tree: No such file or directory
ls: /usr/sbin/tree: No such file or directory
That is the difference between “not installed” and “installed but not found”. If a command is genuinely on the disk and the shell still cannot see it, the problem is your PATH and a different set of checks applies. Here there is nothing to find.
tree is not alone in this. watch, wget, and a number of other tools people reach for out of Linux habit are simply absent, which is a separate matter from the commands that exist but behave differently because macOS ships the BSD versions.
Install it with Homebrew
If you already have Homebrew, this is a ten-second job:
brew install tree
It lands in Homebrew’s bin directory, which is already on your PATH if Homebrew was set up normally. The version installed here reports itself as:
$ tree --version
tree v2.3.2 © 1996 - 2026 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro
Check that number against any tutorial you are following. The 2.x line has options the older 1.x builds most write-ups were based on did not, including the JSON output further down, so a flag that “does not work” may just predate your version.
Installing a single small utility through a package manager is a reasonable trade, but it is worth being clear about what you are agreeing to — Homebrew brings its own directory hierarchy, its own update mechanism, and a habit of pulling in dependencies. If you only ever want a directory listing twice a year, the built-in options further down do the job with nothing installed.
The flags worth knowing
Plain tree against a small project prints the structure and a count:
$ tree project
project
├── docs
│ └── readme.md
├── main.c
├── src
│ └── app.js
└── util.c
3 directories, 4 files
Note what is absent: no .env, no .git. Hidden entries are skipped by default, and the summary line counts only what was printed. Add -a and both the listing and the count change:
$ tree -a -L 2 project
project
├── .env
├── .git
│ └── config
├── docs
│ └── readme.md
├── main.c
├── src
│ └── app.js
└── util.c
4 directories, 6 files
Three flags cover nearly every real use. -L n limits the depth, which is the one that makes the command usable in a large repository — without it, tree in a project with a node_modules folder produces thousands of lines. -d prints directories only. -I pattern excludes matches, and it is the flag to reach for before -L when you know exactly what is noisy:
$ tree -d project
project
├── docs
└── src
3 directories
$ tree -I 'docs' project
project
├── main.c
├── src
│ └── app.js
└── util.c
2 directories, 3 files
For anything programmatic, -J emits JSON instead of box-drawing characters, which pipes straight into jq and avoids parsing output that was designed for human eyes:
$ tree -J -L 1 project
[
{"type":"directory","name":"project","contents":[
{"type":"directory","name":"docs"},
{"type":"file","name":"main.c"},
{"type":"directory","name":"src"},
{"type":"file","name":"util.c"}
]}
, {"type":"report","directories":3,"files":2}
]
The array holds the tree and a trailing report object, and the leading comma on that last element is how tree formats it — valid JSON, unusually laid out.
Making it usable in a real repository
The toy directory above fits on screen. A checked-out project does not, and this is where most people run tree once, get four thousand lines of dependencies, and never run it again. Two options fix that properly.
The first is --gitignore, which reads the repository’s own ignore rules instead of making you restate them. With a .gitignore containing docs/, that directory disappears from the listing without any -I flag:
$ tree --gitignore project
project
├── main.c
├── src
│ └── app.js
└── util.c
2 directories, 3 files
This is the single most useful flag for day-to-day work, because the ignore file is already maintained — build output, dependency folders, and caches drop out automatically and stay out as the project changes. It is also a 2.x feature, which is the practical reason to check tree --version before trusting an older guide.
The second is --du -h, which turns the listing into something closer to a disk-usage report. Sizes are accumulated up the tree, and the summary line changes shape to match:
$ tree --du -h project
[ 468] project
├── [ 96] docs
│ └── [ 0] readme.md
├── [ 20] main.c
├── [ 96] src
│ └── [ 0] app.js
└── [ 0] util.c
468 used in 3 directories, 4 files
Each directory carries the total of everything beneath it, so the heavy branch is visible at a glance rather than after a sort. Combined with -L 2 it answers “what is taking up the space in here” faster than du does, because the structure stays visible.
One last flag for when the output has to leave the Terminal. The default box-drawing characters mangle in anything that is not UTF-8 — a plain-text email, a legacy ticket system, a log file read on another platform. --charset=ascii falls back to characters that survive anywhere:
$ tree --charset=ascii -L 2 project
project
|-- docs
| `-- readme.md
|-- main.c
|-- src
| `-- app.js
`-- util.c
3 directories, 4 files
Also useful when you are redirecting to a file that something else will parse, though -J is the better answer there. And if you want full paths on every line rather than indentation alone, -f prints them, which makes the output greppable at the cost of the shape that made you want tree in the first place.
Without installing anything
Two built-in options get you most of the way. The blunt one is ls -R, which recurses and groups by directory instead of drawing a tree:
$ ls -R project
docs
main.c
src
util.c
project/docs:
readme.md
project/src:
app.js
Readable for something small, unusable past a few levels, but it is there on every Mac and needs nothing explained.
The closer approximation pipes find through sed, turning each path separator into an indent marker:
$ find project -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
project
|____util.c
|____docs
| |____readme.md
|____main.c
|____.env
|____.git
| |____config
|____src
| |____app.js
Two honest differences from real tree. Hidden entries appear, because find makes no distinction — .env and .git are right there in the output above. And the order is filesystem order rather than alphabetical, so two runs on different machines will not match. There is also no summary line. It is a rough substitute, not a drop-in one, and it is worth keeping as an alias for the occasions where installing something is not an option — over SSH into a machine you do not administer, for example.
One trap if you copy that line from elsewhere: sed on macOS is the BSD version, and several common GNU expressions behave differently. The semicolon-separated form above works as written on macOS; a variant using -r or GNU-only escapes will not.
Quick reference
| Goal | Command |
|---|---|
| Install it | brew install tree |
| Limit the depth | tree -L 2 |
| Include hidden entries | tree -a |
| Directories only | tree -d |
| Skip noisy folders | tree -I 'node_modules' |
| Respect .gitignore | tree --gitignore |
| Show sizes per branch | tree --du -h |
| Machine-readable output | tree -J |
| Plain ASCII lines | tree --charset=ascii |
| No install, rough tree | find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' |
| No install, plain listing | ls -R |
In short: brew install tree if you use it regularly, and -L 2 -I 'node_modules' is the combination that makes it pleasant in a real project. If you would rather not install anything, the find pipeline is close enough to read a structure at a glance, as long as you remember it shows hidden files and does not sort.

