Skip to content
shellmap

treePrint a directory tree showing files and subdirectories across all 5 shells

Equivalents in every shell

Bashunix
tree

Linux: install with `apt install tree` (Debian/Ubuntu) or `dnf install tree` (Fedora). macOS: `brew install tree`. NOT pre-installed on either by default — `find . -print | sed -e "s;[^/]*/;|____;g;s;____|; |;g"` is a portable poor-man's substitute. Useful flags: `-L 2` limits depth; `-d` shows directories only; `-a` includes hidden files.

Zshunix
tree

Same external. macOS Homebrew `tree` understands `-I "node_modules|.git"` to EXCLUDE patterns — useful for cleanly diagramming a project root. `tree --gitignore` (newer versions) honors `.gitignore` rules.

Fishunix
tree

Same external. Fish has no built-in tree command. The `eza` modern replacement (`brew install eza`, `apt install eza`) is the recommended successor — `eza --tree --git-ignore --level=2` is the polished modern version of `tree`.

PowerShellwindows
tree /F

Windows pwsh: `tree.com` is BUILT-IN on every Windows install (`C:\Windows\System32\tree.com`) — `/F` includes files, `/A` uses ASCII characters instead of box-drawing. Linux/macOS pwsh has NO `tree` cmdlet — invoke the system `tree` binary if installed, or use `Get-ChildItem -Recurse | Select-Object FullName` as a flat substitute.

cmd.exewindows
tree /F

Built-in `tree.com` since DOS days. `/F` includes files (default is directories only); `/A` uses ASCII. cmd `tree` has no depth limit flag — it always recurses fully. For depth control on Windows, use PowerShell: `Get-ChildItem -Recurse -Depth 2 | Format-Table FullName`.

Worked examples

Print a tree of the current directory, files included

Bash
tree
PowerShell
tree /F
cmd.exe
tree /F

Limit tree depth to 2 levels

Bash
tree -L 2
Zsh
tree -L 2
PowerShell
Get-ChildItem -Recurse -Depth 2 -Directory | Format-Table FullName

Print tree excluding node_modules and .git

Bash
tree -I "node_modules|.git"
Fish
tree -I "node_modules|.git"

Gotchas

  • Windows `tree.com` (the cmd / pwsh built-in) is genuinely DIFFERENT from Unix `tree` — totally separate codebases. Windows `tree` has fewer flags (no `-L`, no `-I`, no `--gitignore`), uses box-drawing characters from a fixed code page (display issues in some terminals), and always recurses fully. The Unix `tree` package is available on Windows via `choco install tree` or scoop, but the executable name overlaps with the built-in — be explicit about which one you call.
  • Unix `tree` is NOT installed by default on most Linux distros (debatable: Ubuntu/Debian Server omits it; some Desktop spins include it) and IS NOT installed on macOS. The portable substitute is `find . -print | awk -F/ '{for(i=1;i<NF;i++)printf "│ ";print "├── " $NF}'` or just `find . -maxdepth N -type d`.
  • Output characters: GNU `tree` uses Unicode box-drawing chars (`├── └── │`) by default — looks good in modern terminals, garbled on legacy/SSH-without-UTF8 sessions. Use `tree -n` for plain ASCII (`|--`, `+--`) on hostile terminals. `tree --charset ascii` is the long form.
  • `tree --gitignore` (GNU tree 1.8.0+) reads `.gitignore` AND `.git/info/exclude` AND global ignore files — handy for "what is THIS project actually made of". Older versions error out with `unknown option`. Check version: `tree --version`.
  • For modern projects with large dependency trees (`node_modules`, `target`, `.venv`), bare `tree` can dump hundreds of thousands of lines. Always default-add a depth limit (`tree -L 3`) or an ignore list (`tree -I "node_modules|.git|dist|build|target|.venv"`) when sharing tree output in a bug report or README.

WSL & PowerShell Core notes

pwshWindows pwsh has `tree.com` (built-in cmd-style); Linux/macOS pwsh has neither built-in tree nor a `Tree` cmdlet — install the system `tree` package, or use `Get-ChildItem -Recurse | Select-Object FullName` as a flat alternative. The modern cross-platform idiom is to `Install-Module PSTree` from PSGallery and use `Get-PSTree`.
WSLInside WSL, `tree` is the standard Linux package — install with `sudo apt install tree`. For a tree view of Windows files from WSL, `tree /mnt/c/Users/me/repo -L 2` works but is slow on large directories due to DrvFs overhead. From Windows pwsh, the built-in `tree.com /F C:\Users\me\repo` is faster for Windows-side trees.

Related commands