How to use “tree command” on linux

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 listsall 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

$ tree

By default, if no argument is provided to tree command, it prints tree of current directory.

Tree example output

Tree example output

Show only the directories:

$ tree -d
Show only directory tree

Show only directory tree

Show all files including hidden dot files:

$ tree -a

Limit the level or depth of recursion:

$ tree -L 2
Limit the level or depth of recursion

Limit the level or depth of recursion

Forward use tree on a directory:

$ tree
Forward use tree on a directory

Forward use tree on a directory

Run man tree for more on how to use tree.

$ man tree
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s