🌳tree command
AYON KARMAKAR

AYON KARMAKAR @ayon_ssp

About: Backend Engineer | I build secure and scalable applications.

Location:
/dev/loop?
Joined:
Feb 15, 2022

🌳tree command

Publish Date: Mar 17 '23
26 2

What is the tree command?

The tree command is a utility tool in Linux that displays the directory structure in a tree-like format. It displays all the subdirectories and files in a hierarchical manner, making it easier to understand the organization of your files and directories.

Installing the tree command

sudo apt-get install tree
Enter fullscreen mode Exit fullscreen mode

How to use the tree command?

tree [options] [directory]
Enter fullscreen mode Exit fullscreen mode

Here, [options] refers to the various options you can use with the command. [directory] refers to the path of the directory whose structure you want to display.

For example, to display the directory structure of the current directory, you can simply type:

tree
Enter fullscreen mode Exit fullscreen mode

Some useful options

Here are some useful options you can use with the tree command:

  • -a: This option will display hidden files and directories as well.
  • -L level: This option allows you to specify the depth to which the directory structure should be displayed. For example, tree -L 2 will display the structure of the current directory and its immediate subdirectories only.
  • -d: This option will display only directories and not files.
  • -I pattern: This option allows you to specify a pattern to exclude files and directories from the tree structure. For example, tree -I '*.txt' will exclude all files with the extension .txt.

Examples:

Example 1: Displaying the directory structure of a specific directory

tree /home/user/Documents
Enter fullscreen mode Exit fullscreen mode

This will display the directory structure of the Documents directory in a

Example 2: Displaying the directory structure of a specific Level 2

tree -L 2
Enter fullscreen mode Exit fullscreen mode

Image description

Comments 2 total

  • Be Hai Nguyen
    Be Hai NguyenOct 17, 2023

    Thank you.

    tree -I '*.txt'
    
    Enter fullscreen mode Exit fullscreen mode

    is particularly useful.

    Best regards,

    ...behai.

  • AudreySkeens
    AudreySkeensOct 15, 2024

    It provides an easy way to see how your files and folders are organized in a tree-like hierarchy, which can be incredibly helpful for navigating complex directories. Bc games

Add comment