How to Install the tree Library to Display Directory Structure in the Terminal
The tree command-line utility allows you to visualize directory structures in a tree-like format directly in your terminal. Below are installation instructions for macOS, Linux, and Windows (via WSL or package managers).
macOS​
Using Homebrew​
- Open Terminal.
- Install tree by running:
brew install tree
- Verify installation:
tree --version
Linux (Debian/Ubuntu)​
- Open Terminal.
- Install tree using APT:
sudo apt-get updatesudo apt-get install tree
- Verify installation:
tree --version
Windows​
Option 1: Using Chocolatey​
- Open PowerShell as Administrator.
- Install tree by running:
choco install tree
- Verify installation:
tree /?
Option 2: Using Scoop​
- Open PowerShell.
- Install tree by running:
scoop install tree
- Verify installation:
tree /?
Option 3: Using Windows Subsystem for Linux (WSL)​
- Follow the Linux installation steps in your WSL terminal.
Usage Example​
Command:​
To display the directory tree of the current folder, simply run:
tree
Output Example:​
Here is an example output for a directory containing multiple files and subdirectories:
.
├── LICENSE
├── README.md
├── docs
│  ├── architecture.md
├── requirements.txt
└── src
├── __init__.py
├── app
│  ├── __init__.py
│  ├── app.py
│  ├── config
│  │  ├── __init__.py
│  │  ├── app_config.py
│  │  ├── config_dev.yml
│  │  ├── config_local.yml
│  │  └── paths.py
│  ├── features
│  │  ├── __init__.py
│  │  └── domain
│  │  ├── __init__.py
│  │  ├── entities
│  │  │  ├── __init__.py
│  │  │  └── user_entity.py
│  │  ├── repositories
│  │  │  ├── __init__.py
│  │  │  └── user_repository.py
│  │  └── value_objects
│  │  ├── __init__.py
│  │  └── email.py
│  └── gunicorn_conf.py
├── main.py
└── shared
├── __init__.py
├── domain
│  ├── __init__.py
│  ├── entities
│  │  ├── __init__.py
│  │  └── base_entity.py
│  ├── repositories
│  │  ├── __init__.py
│  │  └── base_repository.py
│  └── value_objects
│  ├── __init__.py
│  └── entity_id.py
├── global_variables.py
└── utils
├── config_util.py
├── date_util.py
├── log_util.py
├── retry_decorator.py
└── uuid_util.py
17 directories, 44 files