tree
a directory, drawntree 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.
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.
What the numbered lines are telling you
Everything below is drawn relative to it. With no argument, tree starts from the current directory.
Entries drawn beneath src and indented are inside it. The vertical line shows that more entries of the parent follow.
db is a directory, but its contents are a third level and were not shown.
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 -aIncludes hidden entries, whose names begin with a dot.
tree -dShows directories only, leaving the files out.
tree -h --duAdds 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.
Running tree -a on a web root or a repository shows stray .git directories, backups and .env files before someone else finds them.
Without -a, dot files are left out. An audit that skips them skips where secrets usually are.
A tree of a home directory or server reveals user names, software and layout. Trim it before posting it in a public question.