LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

tree

Display directory contents in tree format

TLDR

Display directory tree
$ tree
copy
Show tree for specific directory
$ tree [path/to/directory]
copy
Include hidden files
$ tree -a
copy
Show only directories
$ tree -d
copy
Limit depth of tree
$ tree -L [2]
copy
Show file sizes
$ tree -s
copy
Show human-readable sizes
$ tree -h
copy
Output in JSON format
$ tree -J
copy
Exclude patterns
$ tree -I "[pattern|pattern2]"
copy
Show full path for each file
$ tree -f
copy
Sort by modification time, newest first
$ tree -t -r
copy
Show directory sizes and respect .gitignore
$ tree --du --gitignore
copy

SYNOPSIS

tree [options] [directory...]

DESCRIPTION

tree displays the contents of directories in a tree-like format, showing the hierarchical relationship between files and subdirectories visually.The default output uses ASCII or Unicode box-drawing characters to represent the tree structure. Colorization helps distinguish file types (directories, executables, symlinks, etc.).Various output formats are supported for integration with other tools: JSON (-J) for programmatic parsing, XML (-X) for structured data, and HTML (-H) for web display.Filtering with -I (exclude) and -P (include) uses shell glob patterns, supporting wildcards like \* and ?.

PARAMETERS

-a

Show all files including hidden
-d
List directories only
-L level
Limit depth to level
-f
Print full path prefix
-s
Print size of each file
-h
Print sizes in human-readable format
-D
Print last modification date
-p
Print file permissions
-u
Print username
-g
Print group name
-I pattern
Exclude files matching pattern
-P pattern
List only files matching pattern
--dirsfirst
List directories before files
-C
Colorize output
-n
Turn off colorization
-r
Sort output in reverse order
-t
Sort by last modification time
-o filename
Send output to filename
--du
Show cumulative directory sizes
--prune
Prune empty directories from output
--gitignore
Use .gitignore files for filtering
--noreport
Omit file and directory count at end of listing
--filelimit N
Do not descend directories with more than N entries
-H baseHREF
Output HTML with base URL
-J
Output JSON
-X
Output XML

CAVEATS

Large directories can produce overwhelming output. Use -L to limit depth or -d for directories only when exploring unfamiliar structures.Tree does not follow symbolic links by default if they would cause recursion. Use -l to follow all symlinks.Using --prune and --du causes tree to accumulate the entire tree in memory before output, which may be slow for very large directory trees.

SEE ALSO

ls(1), find(1), du(1), exa(1), eza(1), lsd(1)

Copied to clipboard
Kai