tree flags & options

Basic usage

Show directory structure as a tree.

tree

-L

Limit recursion depth.

tree -L 2
tree -L 3 src/

-a

Show hidden files (dotfiles).

tree -a

-d

List directories only, not files.

tree -d

-I

Exclude files matching a pattern. Use | to separate patterns.

tree -I 'node_modules|dist|.git'

-P

Only show files matching a pattern.

tree -P '*.py'

-s

Show file sizes in bytes.

tree -s

-h

Show file sizes in human-readable format.

tree -sh

-f

Print the full path prefix for each file.

tree -f

-J

Output as JSON.

tree -J -L 2

--dirsfirst

List directories before files.

tree --dirsfirst

-C

Force colorized output (useful when piping).

tree -C | less -R