commands
tree — Display a directory hierarchy
Show directory contents as an indented hierarchy. Hidden names are omitted by default; -a includes them. Limit depth with -L, and use -d for directories only. Symbolic-link targets are not recursively followed by default; avoid -l for unknown trees. Human-readable output is not a stable filename serialization format.
Formal Syntax & Structure
linux syntaxlinux
tree [-a] [-d] [-L LEVEL] [DIRECTORY ...]Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| -a | option | Include hidden entries |
| -d | option | List directories only |
| -L LEVEL | option | Limit recursion depth |
| DIRECTORY | operand | Root directory; default current directory |
Return Value
exit status and output
Hierarchy and summary on stdout; nonzero may indicate a traversal or invocation error. Check stderr.
Working Example
Example Snippetlinux
d=$(mktemp -d) || exit 1trap 'rm -rf -- "$d"' EXITmkdir -p "$d/site/assets"printf "hello\n" > "$d/site/index.html"tree -L 1 "$d/site"