Install
sudo apt install tree
Basic usage
tree
tree /path/to/directory
Depth limit
tree -L 2 # 2 levels deep
tree -L 1 # Only immediate children
Show hidden files
tree -a
Directories only
tree -d
Files only (no dirs)
tree -f
File sizes
tree -h # Human readable
tree -s # Bytes
tree --du # Disk usage
Show permissions
tree -p
Show owner/group
tree -ug
Show full path
tree -f
Sort output
tree -v # Version sort
tree -t # Modification time
tree -c # Last status change
tree -r # Reverse order
tree --dirsfirst # Directories first
Pattern matching
# Include pattern
tree -P '*.txt'
# Exclude pattern
tree -I 'node_modules|.git'
# Multiple excludes
tree -I '*.pyc|__pycache__|.git'
Limit files shown
tree --filelimit 10 # Max 10 files per directory
Output formats
# JSON
tree -J
# XML
tree -X
# HTML
tree -H baseurl > tree.html
Colorize
tree -C # Color (default if terminal supports)
tree -n # No color
Character set
tree --charset ascii # ASCII characters only
Statistics
tree --du # Show size summary
Common use cases
Project structure
tree -L 2 -I 'node_modules|.git'
Config files
tree -a /etc/nginx
Find large directories
tree --du -h | sort -h
Generate documentation
tree -H '.' -L 2 > project-structure.html
Backup verification
tree /backup > backup-structure.txt
Advanced examples
Code project
tree -L 3 -I 'node_modules|dist|build|.git|__pycache__|*.pyc'
With file count
tree -L 2 --dirsfirst | head -50
Size sorted
tree --du -h | grep -v /$ | sort -h
Pipe to file
tree > directory-structure.txt
tree -J > structure.json
Comparison
# Before changes
tree > before.txt
# After changes
tree > after.txt
# Compare
diff before.txt after.txt
Shell alternative
# If tree not available
find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'