List Files 3 Levels Deep in macOS Terminal
Three ways to list files and directories up to 3 levels deep on macOS: tree, find, and ls glob patterns.
Three options for listing files and directories up to 3 levels deep, ordered by readability.
tree (Best Option)
Install via Homebrew (see Homebrew installation guide if needed):
1
brew install tree
List everything up to 3 levels deep:
1
tree -L 3
1
2
3
4
5
6
7
8
> .
> ├── Sources
> │ └── MyApp
> │ ├── App.swift
> │ └── ContentView.swift
> └── Tests
> └── MyAppTests
> └── MyAppTests.swift
Directories only:
1
tree -L 3 -d
find with -maxdepth
No install required — works on macOS and Linux:
1
find . -maxdepth 3
Filter by type:
1
2
find . -maxdepth 3 -type d # directories only
find . -maxdepth 3 -type f # files only
More scriptable than tree — pipe into grep, xargs, or sort as needed.
ls with Glob Wildcards
No extra tools, pure shell expansion:
1
ls -d */*/*
Each * represents one level. Shows only items at exactly the third level — intermediate levels are not listed.
Quick Reference
| Command | Output Style | Dirs Only | macOS Built-in |
|---|---|---|---|
tree -L 3 | Tree view | tree -L 3 -d | ❌ (Homebrew) |
find . -maxdepth 3 | Flat list | -type d | ✅ |
ls -d */*/* | Flat list | Append / | ✅ |
For Xcode project exploration, tree -L 3 -d gives the most readable folder structure at a glance.
☕ Support My Work
If you found this post helpful and want to support more content like this, you can buy me a coffee!
Your support helps me continue creating useful articles and tips for fellow developers. Thank you! 🙏