Skip to main content

Linux tree Command Manual

Overview​

tree is a recursive directory listing command that produces a depth-indented listing of files and directories in a tree-like format.

Installation​

On Debian/Ubuntu:

sudo apt install tree

On Red Hat/Fedora/CentOS:

sudo dnf install tree

On Arch Linux:

sudo pacman -S tree

Basic Usage​

tree [options] [directory]

If no directory is specified, the current directory is used.

Common Options​

OptionDescription
-aAll files are listed (including hidden files)
-dList directories only
-L nLimit display to n levels deep
-fPrint full path prefix for each file
-iDon't print indentation lines
-pPrint file type and permissions
-sPrint size of each file
-hPrint size in human-readable format
-uPrint file owner
-gPrint file group
-DPrint last modification date
--dirsfirstList directories before files
-CAdd color to output
-JOutput in JSON format
-XOutput in XML format
-H TITLEOutput in HTML format with TITLE
--noreportDon't print file/directory report at end
-o FILEOutput to FILE instead of stdout

Examples​

Basic directory listing​

tree

List directories only, 2 levels deep​

tree -d -L 2

List with full path names​

tree -f

List with permissions and size​

tree -p -s -h

List with color and show directories first​

tree -C --dirsfirst

Generate HTML output​

tree -H "My Directory Listing" -o listing.html

Exit Status​

ValueMeaning
0Success
1Minor problem (e.g., cannot stat a file)
2Major problem (e.g., cannot open directory)

Environment Variables​

  • LS_COLORS: Determines colors used for coloring output when -C is used

Files​

  • /etc/DIR_COLORS: Configuration for default color scheme

Author​

The original tree command was written by Steve Baker.

See Also​

  • find(1)
  • ls(1)
  • du(1)