Post

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.

List Files 3 Levels Deep in macOS Terminal

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

CommandOutput StyleDirs OnlymacOS Built-in
tree -L 3Tree viewtree -L 3 -d❌ (Homebrew)
find . -maxdepth 3Flat list-type d
ls -d */*/*Flat listAppend /

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! 🙏

This post is licensed under CC BY 4.0 by the author.