What is the Linux tree command, and how is it used?

Tree command show contents of directories in tree format structure.

What is the Linux tree command, and how is it used?

Tree command help to list out the contents of directories in a tree-like format. Tree command provides tree diagram in-depth listing files.

Most commonly use tree commands in writing documentation, and secondly, we use tree commands to understand project directory structure.

If you use Linux and you think tree command is not your help. Because I have UI to understand every directory. that time, you're mistaken.

Most of the time app or project is very big. Because of many files, folders, or directories in the app, you do not observe and understand what happens in the app., which folder and file whats thing store and secondly, where store my custom components huge directories and folders.

You also face the same problem. Then you are right place. You understand the tree command concept by example.

The most common example. When I build  React.js open-source admin dashboard, I create many custom components and directories for my app., like header, footer, nav, and card directories, to separate every custom component and sass file.

This structure, I understand. But this is an open-source project. When I write documentation for the open-source react dashboard on GitHub. Then I manually design an image to tell others which folder to have a header component you change and where is asset folder is.

This folder or directories structure do not understand
This folder or directories structure do not understand

Right now, I just run the tree command to design a simple tree structure in my command terminal and use it in your documentation.

Linux tree command result
Linux tree command result

How to install tree command?

Firstly check the tree command install by default in your system. so firstly, run it if you face an not found error. After a run command, that means tree command not install in your system firstly install it.

Install tree command in your system in many ways.

  1. Yum
  2. Brew
  3. Snap
  4. Apt


You use it to install the tree command on RHEL/CentOS/Fedora Linux. We have to type the following command on the terminal:

yum install tree 
Install tree in your system.


If we want to install a tree command in the Apple OS system, then type:

Brew install tree 
Install tree in your system.


Install tree command with the help of snapcraft or snap.

sudo snap install tree
Install tree in your system.


The apt command is a common way to install any software and package and widely use it in your system.

 sudo apt install tree
Install tree in your system.

How to use tree command?

Tree program available for Unix and Unix-like systems. That means it is available for all the different platforms like Linux, window, and mac OS.

Tree command also supports all the Linux distro.

Use the tree command is very easy. You write-tree command in your terminal.




sudo tree


tree command output in your terminal
tree command output

Flag and Options

Tree command also provides some flag or option to enhance the working speed. We discuss some tree command options or flags. Whatever you say, but both mean the same.

Some tree flags are handy, and you also use daily basis in life. Other flags are more advance for us. if you are interested to learn more, I recommended using the help command and man command  

tree <directories name>

First, write-tree command. then write directory name

tree -a

This -a flag print All files.  By default, the tree does not print hidden files.

tree -d

This -d flag helps to show only directories List.

tree -f

This -f flag print the full path prefix for each file and directories.

tree -s

Tree -s flag print the size in bytes of each file and directories.

tree --help

The help flag prints help messages in your terminal and automatic exit.

man tree

Man command help to print manual page information on the terminal.

Remove or uninstall the tree command in the system.

You install tree command help of apt command. You uninstall or remove the tree command package in just one command.

rajdeepsingh@officialrajdeepsingh:~$ sudo apt remove --purge tree
remove tree package in your system
  1. Remove flag tell the command to remove this package.
  2. --purge flag help to remove everything related to tree commands like file, folder, and configation.


remove or uninstall tree command in your system
remove tree command in your system