Commands

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

$ tree

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

Tree example output
Show only the directories:

$ tree -d
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

Forward use tree on a directory:

$ tree
Forward use tree on a directory

Run man tree for more on how to use tree.

$ man tree

Related Articles

8 Comments

Leave a Reply to aniqa Cancel reply

Your email address will not be published.

CAPTCHA


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top button