tree draws the contents of a directory as a branching diagram. Learn how `-L` limits the depth, how `-d` shows directories only, and how `-a` reveals hidden files, by running the commands in a real terminal in your browser.
Updated: 2026-09-06
tree [options] [directory]
With no directory it starts from where you are.
$ tree
.
├── docs
│ └── guide.md
├── node_modules
│ └── left-pad
│ └── index.js
├── package.json
├── README.md
└── src
├── components
│ └── Button.js
├── index.js
└── utils.js
5 directories, 7 files
The lines make it obvious which file lives in which directory. The last line counts what it found.
Plain tree walks all the way down, so one big directory such as node_modules fills the screen.
-L says how many levels to open.
$ tree -L 1
.
├── docs
├── node_modules
├── package.json
├── README.md
└── src
3 directories, 2 files
-L 2 opens one level further.
$ tree -L 2
.
├── docs
│ └── guide.md
├── node_modules
│ └── left-pad
├── package.json
├── README.md
└── src
├── components
├── index.js
└── utils.js
5 directories, 5 files
tree -L 2 is a good first command in a repository you have never seen.
-d leaves the files out and draws the directories.
$ tree -d
.
├── docs
├── node_modules
│ └── left-pad
└── src
└── components
5 directories
When the question is how the project is organised rather than what is in it, this is the fastest answer.
Pass a directory to start from there.
$ tree src
src
├── components
│ └── Button.js
├── index.js
└── utils.js
1 directory, 3 files
Names starting with . are left out by default.
-a includes them.
$ tree -a
.
├── .env
├── .gitignore
├── docs
│ └── guide.md
├── node_modules
│ └── left-pad
│ └── index.js
├── package.json
├── README.md
└── src
├── components
│ └── Button.js
├── index.js
└── utils.js
5 directories, 9 files
tree is what you type to get your bearings in a project you have just opened.
| Situation | What to type |
|---|---|
| Look around a new repository | tree -L 2 |
| Check the shape of the project | tree -d |
| Find where the config files live | tree -a -L 1 |
| Look at one directory | tree src |
| Make a diagram for the README | tree -L 2 > structure.txt |
-L needs a number.
$ tree -L 0
tree: Invalid level, must be greater than 0.
Give it 1 or more.
It only takes directories.
$ tree nope
tree: nope: No such file or directory
It is often not installed.
Unlike ls or cd, tree has to be added on many systems.
When a server does not have it, ls -R is the fallback.
You lose the branches, but you still get everything below the current directory.
webterm.appthis site
Advanced Terminal Commands
Learn commands for specific situations
learn.webterm.appa separate site

Commands stick when they show up in a real sequence of work, not one at a time. There is a course that builds them up in order.
See the course