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

NameTypeDescription
-aoptionInclude hidden entries
-doptionList directories only
-L LEVELoptionLimit recursion depth
DIRECTORYoperandRoot 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"
Linux Reference