Install the Debian Package of tree in Ubuntu

16 April 2025

1_healthytip

How often do you feel lost in the never-ending hierarchy of folders? Working with huge projects or examining new codes can be a tough task. The tree command really comes in handy here by displaying your directories in a visual way.

This article instructs Ubuntu users on installing and using tree. Its interface offers basic and advanced features, and you shall learn to navigate your system like a pro.

Why Use the tree Command?

tree makes understanding your directory structure easy. Instead of long lists, you get a clear picture of your workings. The visualization enhances your navigation speed. Finding files and folders becomes way easier. Also, playing detective with a problem is easier when you have a good view of everything.

Think about how much time you spend browsing folders. The tree command could save you some time and probably stress!

Understanding Directory Structures

tree displays directories and subdirectories in a tree-like structure. It is like a family tree, but of your files. Each branch represents a folder. The leaves represent files that sit within those folders.

Say, for example, you execute the command tree inside your home directory so it can list something like this:

.
├── Documents
│ ├── report.txt
│ └── presentation.pdf
├── Downloads
├── Music
└── Pictures
└── vacation.jpg

This output shows the major directories of your home folder.

Advantages Over Traditional Methods

Sure, you can use the ls alternative; it lists the contents of a directory, but after some time, it will get all messy in your mind. You can see only one level at a time. With tree, you can see many levels of directories. The visual aspect really helps. So much better than running ls command after ls command!

How To Install tree In Ubuntu

Tree installation is very easy. You will do that from the command line. For best results, copy-paste the below command.

Updating Package Lists

Before installing anything, do run the package lists for updates, so that we have the latest version of that info. Fire up the terminal and type in

sudo apt update

This command updates the list of packages that are available now.

Installing tree

Now you should install tree: Implementation in the terminal will be as follows:

sudo apt install tree

The system will ask for your password; key it in and hit enter. The tree package will now download and install.

Basic Usage of the tree Command

It’s time for some tree action! Here are some pretty basic commands to get you started. Experiment with these on your own system to see how they work.

Display the Directory Tree

To see the tree structure of the directory, use the following command:

tree /path/to/directory

Direct substitution of /path/to/directory with the real thing. If you are looking for something in your current directory, just type in:

tree

Limiting the Tree Depth

Sometimes you only want to look at a few levels. The -L option will limit how deep you will venture in. For instance, if it were limited to two levels, do:

tree -L 2 /path/to/directory

Go through experimenting with different depths and find out which one suits you best.

Advanced Options for the tree Command

tree has even more to offer. These advanced options allow filtering and customizing the output.

File Type Filtering
To filter files, use the options -P and -I. -P filters to show matching files to the pattern, while -I filters out to ignore files matching a pattern.

To show .txt files specifically, you run:

tree -P “*.txt”
To filter out the node_modules folder, type:

tree -I “node_modules”
Displaying Hidden Files
By default, the tree command will not show hidden files (files starting with a dot). You may use -a to show them:

tree -a
Now, every file will be visible, including hidden ones.

Customizing tree Output
Another thing tree can be customized for is the output and visuals.

Using Different Character Sets
-n option for no color, and -A for ASCII characters will do here. They may come in handy depending on whether or not you are fortunate enough to be operating in an environment that recognizes colors.

To get rid of colors, enter:

tree -n
If you want ASCII characters, write it this way:

tree -A
Displaying File Sizes
With the -s option, you’ll see each file’s size:

tree -s
This is going to append the file size to the output. Now you know how heavy each of the files is.

Conclusion
Installing and using a command tree in Ubuntu is a breeze: update the package lists, install the tree package, and begin exploring. Options can be further used to filter, customize the output, and represent the tree in other ways.

The tree command definitely reduces the navigation and handling of directories. Give it a try and see how it works for you.