Oliver Wolfson
ServicesProjectsContact

Development Services

SaaS apps · AI systems · MVP builds · Technical consulting

Services·Blog
© 2026 O. Wolf. All rights reserved.
The Tree Terminal Command Utility
The tree command is a powerful tool for visualizing the directory structure of your filesystem in a tree-like format. Unlike standard listing tools like ls, tree displays nested folders and files with indentation, making it easy to understand the layout of your project at a glance.
August 5, 2025•O. Wolfson

The tree command is a powerful tool for visualizing the directory structure of your filesystem in a tree-like format. Unlike standard listing tools like ls, tree displays nested folders and files with indentation, making it easy to understand the layout of your project at a glance.

The tree command displays directory structures in a tree-like format.

1. Basic Usage

tree

This prints the directory tree from the current folder.


2. Exclude a Folder

Use the -I (capital i) option with a pattern to exclude files or folders:

tree -I 'folder_to_exclude'

Multiple excludes: Separate with | (pipe):

tree -I 'node_modules|dist|venv'

3. Limit Number of Items Printed

Use the -L option to limit the depth of recursion (how deep tree goes):

tree -L 2

This prints 2 levels (current dir and its immediate subfolders).

To limit number of items per folder (not depth): There is no built-in option in tree for “max items per folder”, but you can combine with head:

tree | head -n 20

This will print only the first 20 lines of tree output.

Or, for more custom filtering (for advanced users), consider using ls with head:

ls | head -n 10

But this doesn't provide a tree structure.


Common Examples

  • Exclude node_modules and show only 2 levels deep:

    tree -I 'node_modules' -L 2
    
  • Show only top 10 lines of tree output:

    tree | head -n 10
    

Summary Table

FeatureOption/Command
Exclude foldertree -I 'folder'
Exclude multiple folders`tree -I 'folder1folder2'`
Limit depth (levels)tree -L N
Limit items per folderNot supported directly
Limit output lines`treehead -n N`