Introduction
In the day to day of administrators and developers, quickly knowing the hierarchy of folders and files is essential for browsing, debugging or documenting projects. The commandtreeoffers a tree-shaped visual view that shows the directories structure in a clear and compact way, avoiding the need to run multiplelsorfind. In this article you will learn what it istree, how to install it, its basic syntax and practical examples that you can immediately apply to your terminal.
What's tree?
treeis a small command line utility that recursively runs a directory and generates a graphic representation of its content using characters like|, ─and└. Each depth level is indicated with bleeding, which allows quick identification of subfolders, files and their permissions. Although not pre-installed in all distributions, its installation is simple and its resource consumption is minimal.
Installation
In Debian / Ubuntu-based distributions, just run:
sudo apt update && sudo apt install tree
In Fedora or CentOS / RHEL is used:
sudo dnf install tree # Fedora
sudo yum install tree # CentOS/RHEL
In Arch Linux and derivatives:
sudo pacman -S tree
After installation, the command is available globally and can be invoked simply by writingtreeAt the terminal.
Basic syntax
The simplest way is:
tree [opciones] [directorio]
If a directory is not specified,treeworks on the current directory (.). Some common options are:
-a: displays all files, including hidden files (starting with.).-d: list only directories, ignoring files.-L nivel: limits the depth of the route to the number indicated.-p: shows the permissions of each file.-h: indicates file size in legible format (KB, MB, etc.).--dirsfirst: first list the directories and then the files.
Common examples
1. See the complete structure of the current project:
tree
2. Limit depth to two levels:
tree -L 2
3. Show only directories, useful for a quick look at the hierarchy:
tree -d4. Include sizes and permissions:
tree -ph5. Exclude certain patterns (e.g. directories)
node_modules):
tree -I 'node_modules|*.log'6. Save output in a file for documentation:
tree -a > estructura.txtAdvanced options and tricks
For users who require more control,
treeallows to combine several options and use regular expressions in exclusion / inclusion filters. For example, to show only files with extension.pyand their parents' directories:
tree -P '*.py'If you want colors on the output (depending on the capacity of your terminal), add
--charsetor make sure the variableTERMsupport colors; many distributions already enable it by default.In scripts, you can combine
treewithgreporawkto extract specific information, such as counting how many files of a type exist:
tree -fi | grep '\.txt$' | wc -lHere,
-fshows the complete route of each input and-iremoves the bleeding lines, leaving a flat list easy to process.Conclusion
The command
treeis a light but powerful tool that improves productivity by providing an instant view of the structure of files and directories. Its installation is trivial in most Linux distributions and its options allow to adapt the output to almost any need, from a simple view of folders to detailed reports with permissions and sizes. Incorporatestreein your daily workflow and you will notice how long you save by avoiding repetitive commands oflsandfind.


