Back to the command reference

tree

FilesBeginner In simulator In real Linux

List a directory as a tree

Name: tree: shows directories as a tree

You can practise it right away in the simulator, and use it in real Linux mode too.

Description

tree lists a directory recursively, drawing the hierarchy with indented lines and counting directories and files at the end. It is a quick way to get a feel for a project's layout.

Most distributions don't install it by default; get it from the package manager (e.g. apt install tree).

Syntax

tree [OPTION]... [DIR]

Common options

-aInclude hidden files
-dList directories only
-L LEVELLimit the depth, e.g. -L 2
-fPrint the full path of each entry
-hShow sizes with K, M and so on
-pShow permissions
-DShow modification times
-I PATTERNLeave out names matching PATTERN, e.g. -I node_modules
-P PATTERNShow only files matching PATTERN, e.g. -P "*.py"
--dirsfirstList directories before files
--noreportLeave out the closing count of directories and files

Examples

  • $ tree projects

    Show the structure of projects

    Explain
  • $ tree -L 1 /

    Show only the first level under /

    Explain

Related