--- title: tree โ€” Visualize Directory Structure date: 2026-10-18 time: 12:00 model: admin category: programs author_type: human summary: Command that displays the folder structure as a tree. Useful for root cause analysis and documentation. tags: program, File and disk management, tree --- **๐Ÿ’ฌ "tree command"** tree shows the directory structure **in a hierarchical shape**. It is faster to understand the structure than running ls multiple times. Use it to quickly check the structure of directories where logs accumulate or deployment artifacts. - **Concept**: Outputs subdirectories and files in a tree format starting from the specified path. - **Left side**: Represents hierarchy with connector lines like `โ”œโ”€โ”€`, `โ””โ”€โ”€`. - **Last line**: Summarizes the number of directories and files. - **Depth**: You can limit how many levels to view with the -L option. ## Commonly Used Options | Option | Description | | --- | --- | | -L | Limits depth to n levels | | -d | Displays directories only | | -h | Displays file sizes in human-readable units | | --du | Displays cumulative size by directory | | -a | Displays hidden files as well | ## 3 Essential Command Combinations - `tree -L 2 /var/www/html` โ€” Check the web root structure up to 2 levels only - `tree -d -L 2 /opt/app` โ€” View only directories to understand the structure - `tree --du -h /var/log | head -30` โ€” Check size by log directory **๐Ÿ’ฌ "Which options should be used together to reduce mistakes?"** Here are situations commonly encountered on a live server, organized in order. ### Step 1 ยท View the Structure at a Glance Limit the depth to understand the overall layout. ``` tree -L 2 /var/www/html ``` ### Step 2 ยท View with Sizes Check which subfolders are large. ``` tree --du -h -L 2 /var/log ``` ### Step 3 ยท Save as Documentation Save the structure to a file for review or handover. ``` tree -L 3 /opt/app > /tmp/app-structure.txt ``` ## How This Is Used in Practice ### 1. Verify Deployment Structure **Situation** โ€” You unpacked a release archive, but the file layout is different from expected. ``` tree -L 2 /opt/app/releases/20261018 ``` **Result** โ€” If public/ should be at the top level but a subfolder goes one level deeper, it is an archive path issue. **Point** โ€” The habit of checking with tree after deployment helps you quickly find the cause of 404/500 errors. ### 2. Identify Where Log Data Accumulates **Situation** โ€” The disk is full, so you check which log directory is large. ``` tree --du -h -L 2 /var/log | sort -k2 -h | tail ``` **Result** โ€” Identify the large subdirectories and decide what to rotate. **Point** โ€” Because tree's --du shows recursive totals, it is convenient for judging at the folder level. ## Things to Keep in Mind - If you run tree without options in a directory with tens of thousands of files, the output explodes. Limit it with -L. - tree is not always installed by default, so if the tree command is missing, you need to install the package. - If the output is long, trim it with head/tail. ## Actual Execution Screen This is the result of checking the two-level structure of the web root. ![tree command execution result: directory tree structure](https://games.aidebatehub.com/assets/tree-demo.png) A live production server --- Source (HTML): https://games.aidebatehub.com/programs/linux/filesystem/tree.html This file is an auto-generated Markdown twin of the DevHub document.