tree(1)
Display directory structure as a tree with indented lines showing files and subdirectories.
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
| Flag | What it does |
|---|---|
-L <depth> | Limit recursion depth to N levels (e.g., -L 2 shows 2 levels deep) |
-d | List only directories, omit files |
-a | Print all files including hidden files starting with a dot |
-I <pattern> | Exclude files matching the pattern (e.g., -I '.git|node_modules') |
-h | Print human-readable file sizes (KB, MB, GB) |
-s | Print file sizes in bytes along with filenames |
-u | Display file owner and permissions (like ls -l) |
-t | Sort by modification time instead of filename |
-r | Sort in reverse alphabetical order |
-x | Stay on the current filesystem; don't descend into other filesystems |
-J | Output as JSON instead of tree format |
--du | Display cumulative disk usage for each directory |
Examples
Display entire directory structure of current folder with ASCII tree lines
treeShow directory tree limited to 2 levels deep
tree -L 2Display only directories up to 3 levels deep, no files
tree -d -L 3Show all files including hidden ones, but exclude .git directory
tree -a -I '.git'List files with human-readable sizes and byte counts
tree -h -sShow tree with file permissions and owners for the project directory
tree -u /home/user/projectDisplay tree 2 levels deep, excluding common build/dependency folders
tree -I 'node_modules|.git|dist' -L 2Export directory structure to JSON file for programmatic processing
tree -J > structure.json