Tree is a program available for Unix and Unix-like systems. tree is a recursive directory listing program that produces a depth-indented listing of files.
With no arguments, tree lists the files in the current directory. When directory arguments are given, tree lists all the files and/or directories found in the given directories each in turn. Upon completion of listing all files/directories found, tree returns the total number of files and/or directories listed.
In this article we will show at how to list contents in a directory as the the title implies in a tree format.
Install tree command
By default the tree command is not installed. Type following command to install tree command on RHEL/CentOS and Fedora linux:
# yum install tree -y
If you are using Debian/Ubuntu, Mint Linux type following command in your terminal:
$ sudo apt-get install tree -y
Using tree command
To view directory structure of a directory in tree format, use tree command as
By default, if no argument is provided to tree command, it prints tree of current directory.
Show only the directories:
$ tree -d
Show all files including hidden dot files:
$ tree -a
Limit the level or depth of recursion:
$ tree -L 2
Forward use tree on a directory:
Run man tree for more on how to use tree.
$ man tree