Working in a command-line terminal on a Linux cloud server, bare-metal deployment, or Docker container and typing tree to visually inspect nested directory hierarchies only to receive the shell alert bash: tree: command not found (or sh: tree: not found) interrupts filesystem navigation. The tree utility is a recursive directory listing program that outputs a depth-indented visual graph of files, subdirectories, and symlinks directly in the terminal. Because standard minimal server images and cloud-init container base layers exclude optional command-line utilities to minimize container image sizes, tree is not bundled by default. Installing the package via official repository mirrors or utilizing built-in find fallback commands enables instantaneous directory visualization.
Install tree on Ubuntu, Debian, and Linux Mint
Debian-based distributions maintain official pre-compiled tree binaries within their main repository mirrors.
- Log into your server terminal as a privileged user or prepend commands with
sudo. - Update your local package repository index:
sudo apt update - Install the tree utility package:
sudo apt install -y tree - Verify successful binary deployment and check the version:
tree --version - Execute a test run limiting directory depth to two levels:
tree -L 2
Install tree on RHEL, Rocky Linux, CentOS, and Alpine
Enterprise Linux platforms and lightweight container environments deploy the utility using native package managers.
- On RHEL 8/9, Rocky Linux, or AlmaLinux, install tree using DNF:
sudo dnf install -y tree - On older CentOS 7 distributions, install using Yum:
sudo yum install -y tree - On lightweight Alpine Linux containers, deploy via apk:
apk update && apk add tree - On Arch Linux, execute:
sudo pacman -S --noconfirm tree
Use Native find and sed Commands as an Instant Alternative
If you are operating in an air-gapped system, unprivileged container, or environment without package installation privileges, built-in shell tools replicate tree output.
- Execute the following one-line shell pipeline to generate an indented visual directory structure:
find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' - Alternatively, use native
lswith recursive grouping flags:ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^/]*//--/g' -e 's/^/ /' -e 's/-/|/' - These native POSIX pipelines run immediately across all Linux distributions without requiring root permissions or external network package downloads.