Home·Terminal commands

tree

Files and directories

Usage

tree -L 2 [path]

Draws the directory structure as an indented picture; it is not installed by default on macOS or slim Linux images.

Common flags

FlagMeaning
-LLimit the depth to N levels
-aInclude hidden files
-dDirectories only
-ISkip names matching a pattern
-fPrint the full path of each entry
-hShow readable sizes

Examples

tree -L 2

Two levels deep, so the output stays readable.

tree -I 'node_modules|.git'

Skips the noisy directories.

tree -d -L 1

Just the top-level folders.

Moving, deleting and finding. Some of these do not ask twice, which is why -i becomes a habit.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does tree do?

Draws the directory structure as an indented picture; it is not installed by default on macOS or slim Linux images.

Q. How do I type it?

tree -L 2 [path] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

6 are listed here; the full set is in man tree. This command sits under Files and directories.

Related commands

man page: man tree