How to View Directory Trees with the tree Command
The tree command prints a directory's structure as an indented tree with branch lines. Run tree in a project and you see every folder and file in one view. It is the fastest way to understand a new codebase or check what a folder contains.
Print a directory tree
tree shows the current folder by default. Give it a path to view another folder. The output ends with a summary of how many directories and files were listed.
Limit the depth with -L
Big trees are overwhelming. -L 2 shows only two levels, which is usually enough to grasp the structure.
Show directories only with -d
To see just the folders, add -d. This is the fastest way to map a project's structure without file noise.
Include file sizes with -h
Add -h to print a human-readable size next to every file. Pair it with -s for exact bytes.
Save a tree to a file
Redirect the output to document your structure in a README: tree -L 2 > structure.txt. If tree is not installed, it is usually one apt away. See tree for all options.
Keep learning
Related guides: The Linux ls Command: List Files Like a Pro · How to Find Files and Directories with the Linux find Command · How to Check Disk Usage with df and du. Read all tutorials on the Learn Linux blog.