Skip to content

The Tree Command

Static Badge

Installing the tree command

The tree command is not installed by default. to use it, we have to install it first.

Open a terminal (by pressing Ctrl + Alt + t ) and run the following command:

sudo apt update; sudo apt install tree
These are, actually, two commands: the first one updates the package manager's (apt) local cache, and the second one, after the semicolon (;), actually installs the tree command.

When you run the tree command without any arguments, it lists the contents of the current directory and it's sub-directories:

Example command output:
.
├── Desktop
├── Documents
│   ├── bills
│   │   ├── 2025
│   │   │   ├── 01.pdf
│   │   │   ├── 02.pdf
│   │   │   ├── 03.pdf
│   │   │   ├── 04.pdf
│   │   │   ├── 05.pdf
│   │   │   ├── 06.pdf
│   │   │   ├── 07.pdf
│   │   │   ├── 08.pdf
│   │   │   ├── 09.pdf
│   │   │   ├── 10.pdf
│   │   │   ├── 11.pdf
│   │   │   └── 12.pdf
│   │   └── 2026
│   │       ├── 01.pdf
│   │       ├── 02.pdf
│   │       ├── 03.pdf
│   │       ├── 04.pdf
│   │       ├── 05.pdf
│   │       ├── 06.pdf
│   │       ├── 07.pdf
│   │       ├── 08.pdf
│   │       ├── 09.pdf
│   │       ├── 10.pdf
│   │       ├── 11.pdf
│   │       └── 12.pdf
│   └── contract.pdf
├── Downloads
│   └── google-chrome-stable.deb
├── Music
├── Pictures
│   └── cat.jpg
├── Public
├── Templates
└── Videos
    └── cute_cat.mp4

12 directories, 28 files
As seen in the example output, the tree command displays all of the files inside the sub-directories too. This can get quite a long list...

Tip

If you are running Linux right now, go ahead: Open a Terminal on your own computer and run the tree command without any arguments. I bet you'll see a very long list of files whiz by your screen 😯

Command Syntax Examples

There aren't many useful arguments for this command, but here are a few practical ones for a daily workflow:

To list all files, including hidden ones:

tree -a
To list only directories:

tree -d

Descend only level directories deep.

tree -L <level>
Replace <level> with a number of levels you want to drill into a directory tree.
Notice there's a space between the -L and the number.

To filter files in a .gitignore file :

tree --gitignore

This one is very handy for filtering out all files and directories already contained in your project's .gitignore file.

Output to file instead of stdout:

tree -o <path/to/file.txt>

CONCLUSION

This is only a short introduction to the tree command. This is a very powerful command, especially useful for gathering information about your file system structure, say, if you are looking for a lost file or want to get a clear picture before a spring cleaning of your /home directory.

As usual, you can find out more by reading the manual page (man tree), or by researching online for specific scenarios and use cases.