Vol. I · No. 46The command line sectionSat, 10 Oct 2026
Linux · navigation

tree

a directory, drawn

tree lists a directory recursively and draws the nesting with lines, so the shape of a project is visible at a glance. It is not installed by default on most systems — one package away.

ls shows one level; tree shows how the levels fit together.

Shows
Nested layout
directories and files
Limit depth
-L NUM
or large trees scroll for ever
Ends with
A count
directories and files
Install
apt install tree
or dnf install tree

At the terminal

Read the session first, then the notes: each numbered line in the output is answered by the note with the same number.

user@netflow — bashtree
$ tree -L 2 project
1project
├── README.md
2├── src
│ ├── app.py
3│ └── db
└── tests
└── test_app.py
 
43 directories, 3 files
Illustrative session · names, sizes and dates are examples, and every address is from a documentation or private range
Reading the output

What the numbered lines are telling you

1
The starting directory

Everything below is drawn relative to it. With no argument, tree starts from the current directory.

2
A branch is a directory

Entries drawn beneath src and indented are inside it. The vertical line shows that more entries of the parent follow.

3
-L 2 stopped here

db is a directory, but its contents are a third level and were not shown.

4
The summary line

The starting directory itself is not counted: src, db and tests are the three.

Switches

A switch changes how the command behaves. These are the ones used day to day; man tree lists the rest. Single-letter switches can usually be joined, so -l -a may be written -la.

-L NUM
Descend only NUM levels deep.
-a
All: include hidden entries.
-d
List directories only.
-h
Print each file’s size in readable units.
-f
Print the full path of each entry.
-I PATTERN
Leave out entries matching the pattern.

Variations worth knowing

The same tool, pointed at a narrower question. These four cover most of what it is reached for day to day.

tree -a

Includes hidden entries, whose names begin with a dot.

tree -d

Shows directories only, leaving the files out.

tree -h --du

Adds sizes, with each directory showing the total of its contents.

tree -I "node_modules|.git"

Leaves out anything matching a pattern.

In cybersecurity

A drawn tree is the fastest way to notice what should not be there.

Review before publishing

Running tree -a on a web root or a repository shows stray .git directories, backups and .env files before someone else finds them.

Hidden is only hidden from ls

Without -a, dot files are left out. An audit that skips them skips where secrets usually are.

Pasting output

A tree of a home directory or server reveals user names, software and layout. Trim it before posting it in a public question.

Filed under

Navigation

Read alongside