Linux command list

tree command: see the directory structure as a diagram

__ __ _ _____
\ \ / /__| |_|_ _|__ _ __ _ __ ___
\ \ /\ / / _ \ '_ \| |/ _ \ '__| '_ ` _ \
\ V V / __/ |_) | | __/ | | | | | |
\_/\_/ \___|_.__/|_|\___|_| |_| |_| |_
 
A sandbox for trying tree. Nothing here can touch your real files.
user@webterm:~/project$
 

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

Syntax

tree [options] [directory]

With no directory it starts from where you are.

Try it first

$ 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.

Limiting the depth

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.

Directories only

-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.

Looking at one part

Pass a directory to start from there.

$ tree src
src
├── components
   └── Button.js
├── index.js
└── utils.js

1 directory, 3 files

Showing hidden 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

When you actually reach for it

tree is what you type to get your bearings in a project you have just opened.

SituationWhat to type
Look around a new repositorytree -L 2
Check the shape of the projecttree -d
Find where the config files livetree -a -L 1
Look at one directorytree src
Make a diagram for the READMEtree -L 2 > structure.txt

Things that trip people up

-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.

Practise it hands-on

webterm.appthis site

  • Advanced Terminal Commands

    Learn commands for specific situations

    Try the tutorial

learn.webterm.appa separate site

>_WEBTERM LEARN

WebTerm Learn: from one command to actually using it

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

Related commands

ls / find / du / cd

Frequently asked questions

How is tree different from ls -R?
They show the same thing, but tree draws the branches, so you can follow what sits inside what. Only tree can cut the depth with `-L`.
node_modules fills my whole screen.
Limit the depth with `tree -L 2`. If you only care about the shape of the project, `tree -d` drops the files entirely.
How do I see hidden files?
`tree -a`. Names beginning with a dot, such as `.env` and `.gitignore`, then show up.
My server says tree is not found.
It is not installed by default on most Linux systems. On Ubuntu or Debian, `sudo apt install tree` adds it. The terminal on this page has it already.
How do I put the diagram in a README?
Write it to a file first, as in `tree -L 2 > structure.txt`, then paste that. Cutting the depth keeps the diagram readable.