tree Command: Navigating Directory Structures

December 11, 2023

Command Overview

tree -I tmp -C
  • tree: This is a command-line utility that displays the contents of a directory in a tree-like format.
  • -I tmp: This option is used to exclude a specific pattern or directory from the tree view. In this case, it excludes any directories or files with the name "tmp."
  • -C: This option is used to colorize the output, making it more visually appealing by using different colors for different types of files.
Tree Command Output Example

Installation

Install tree command using Homebrew:

brew install tree

Common Options

Option Description
-a Show all files (including hidden)
-d List directories only
-L n Limit depth to n levels
-f Print full path prefix

Use Cases

  • Project structure documentation
  • Directory navigation
  • File system exploration
  • Project organization

Example Commands

# Show only directories
tree -d

# Limit depth to 2 levels
tree -L 2

# Exclude multiple patterns
tree -I 'node_modules|tmp|cache'

# Show with file size
tree -sh

Tips

  • Use patterns to exclude unwanted directories
  • Combine options for specific needs
  • Redirect output to file for documentation
  • Use color output for better visibility
#CLI #Unix #Tools #Filesystem