bash: tree command not found in CentOS / Linux / Docker

Troubleshooting tree command not found in CentOS / Linux / Docker

Error Message:

bash: tree: command not found

If you get an error bash: tree: command not found in your Linux box, there is a way to install it, provided you have root access

The solution: Installing tree command in CentOS using Yum repository

If you can install tree command, follow the below-given steps, if you cant install tree, such as lightweight containers such as Docker, there are alternative methods

yum install tree

Demonstrating yum install tree command

[[email protected] ~]# yum install tree
Loaded plugins: fastestmirror
Determining fastest mirrors
* base: centos.xxxx
* extras: centos.xxxx
* updates: centos.xxxxxx
base                                                                                                              | 3.6 kB  00:00:00
extras                                                                                                            | 2.9 kB  00:00:00
updates                                                                                                           | 2.9 kB  00:00:00
(1/4): extras/7/x86_64/primary_db                                                                                 | 153 kB  00:00:00
(2/4): base/7/x86_64/group_gz                                                                                     | 165 kB  00:00:00
(3/4): updates/7/x86_64/primary_db                                                                                | 2.8 MB  00:00:02
(4/4): base/7/x86_64/primary_db                                                                                   | 6.0 MB  00:00:06
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================================================
Package                       Arch                            Version                               Repository                     Size
=========================================================================================================================================
Installing:
tree                          x86_64                          1.6.0-10.el7                          base                           46 k

Transaction Summary
=========================================================================================================================================
Install  1 Package

Total download size: 46 k
Installed size: 87 k
Is this ok [y/d/N]:

Give Y to continue

Downloading packages:
tree-1.6.0-10.el7.x86_64.rpm                                                                                      |  46 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : tree-1.6.0-10.el7.x86_64                                                                                              1/1
  Verifying  : tree-1.6.0-10.el7.x86_64                                                                                              1/1

Installed:
  tree.x86_64 0:1.6.0-10.el7

Complete!

Testing tree command with a practical example

[[email protected] ~]# tree
.
├── anaconda-ks.cfg
├── PASSWORD.zip
├── test
│   ├── files1.txt
│   ├── files2.txt
│   ├── files3.txt
│   ├── files4.txt
│   ├── files5.txt
│   ├── files6.txt
│   ├── files7.txt
│   ├── files8.txt
│   └── files9.txt
├── tester.sh
└── zipfile.zip

1 directory, 13 files

Yum, the command will work in CentOS8, CentOS 7, CentOS 6, Linux, RHEL, and Fedora Linux flavors.