$linuxjunkies
>

tree(1)

Display directory structure as a tree with indented lines showing files and subdirectories.

UbuntuDebianFedoraArch

Synopsis

tree [OPTION]... [DIRECTORY]...

Description

tree is a recursive directory listing program that produces a depth-indented listing of files and directories, visualized with ASCII or Unicode lines to show the tree structure. It's useful for understanding directory hierarchies and presenting folder layouts clearly.

By default, tree lists all files and directories. It supports filtering by name patterns, file types, depth limits, and various output formats including JSON and XML.

Common options

FlagWhat it does
-L <depth>Limit recursion depth to N levels (e.g., -L 2 shows 2 levels deep)
-dList only directories, omit files
-aPrint all files including hidden files starting with a dot
-I <pattern>Exclude files matching the pattern (e.g., -I '.git|node_modules')
-hPrint human-readable file sizes (KB, MB, GB)
-sPrint file sizes in bytes along with filenames
-uDisplay file owner and permissions (like ls -l)
-tSort by modification time instead of filename
-rSort in reverse alphabetical order
-xStay on the current filesystem; don't descend into other filesystems
-JOutput as JSON instead of tree format
--duDisplay cumulative disk usage for each directory

Examples

Display entire directory structure of current folder with ASCII tree lines

tree

Show directory tree limited to 2 levels deep

tree -L 2

Display only directories up to 3 levels deep, no files

tree -d -L 3

Show all files including hidden ones, but exclude .git directory

tree -a -I '.git'

List files with human-readable sizes and byte counts

tree -h -s

Show tree with file permissions and owners for the project directory

tree -u /home/user/project

Display tree 2 levels deep, excluding common build/dependency folders

tree -I 'node_modules|.git|dist' -L 2

Export directory structure to JSON file for programmatic processing

tree -J > structure.json

Related commands