tree Show folders and files as an indented tree
Prints a folder and everything inside it as an indented tree, so you can see the whole layout at a glance. You reach for it to explain a project structure or to check what a folder contains several levels down. It ends with a count of directories and files.
Synopsis
tree [OPTION]... [DIRECTORY]...
Common options
| Option or form | What it does |
|---|---|
-L LEVEL | Limit how many levels deep to go. -L 1 shows only the top level |
-a | Include hidden files (names starting with a dot). They are skipped by default |
-d | List directories only, no files |
-I PATTERN | Ignore names matching a pattern. Separate several patterns with |, for example 'node_modules|.git' |
-P PATTERN | Show only files matching a pattern, such as '*.md'. Folders are still shown |
-h | Print file sizes in human-readable form such as 4.0K |
-f | Print the full path of each entry instead of just its name |
--dirsfirst | List folders before files |
Examples
tree
tree -L 2
tree -d -L 2 docs
tree -h --dirsfirst photos
tree -P '*.md' docs
tree -a -I 'node_modules|.git' -L 3
Notes
- tree is not installed by default on macOS or on many Linux systems. Install it with brew install tree on macOS, or sudo apt install tree on Debian and Ubuntu. If you cannot install it, find . -type d gives a flat list of folders.
- Because tree may be missing, none of the examples on this page are run automatically.
- On a big folder, plain tree prints thousands of lines. Start with -L 2 and go deeper only if you need to.
- -P and -I take shell-style patterns, not regular expressions. Quote them so the shell does not expand them first. -P filters files only, so folders that contain no matches still appear unless you add --prune.
- By default tree does not follow symbolic links into folders. Use -l if you want it to. Colours are off when output goes to a file or pipe, and -C forces them on.
See also
Last reviewed 2026-10-07.