Command tree: Show directories as a tree in Linux

Sometimes navigating the Linux directories from the console becomes a bit complicated, in addition, in some cases we need to know the structure of some directories, the natural way to improve this is by showing the directories in the form of a tree.

Showing directories as a tree in Linux is quite simple, thanks to the utility tree, which is not installed by default in most Linux distributions but is found in the official repositories.

tree-shaped directories

tree-shaped directories

What is the tree command?

It is a command widely used by Linux users, which allows us to show the hierarchy of our operating system's directories in a graphical and structured way.

The tree command also allows you to list the directories of the external devices.

Installing the tree command on Linux

In some distros the tree command is installed by default, but in most cases this is not the case, in most cases it is enough to install it using the repositories of each distro.

You can use any of the following commands to install it on your favorite distro.

$ sudo pacman -S tree # Arch Linux
$yum install tree -y #Centos y Fedora
$ sudo apt-get install tree # Ubuntu  
$ sudo aptitude install tree # Debian

You can ensure that the installation was completed successfully by running the tree command

How to use the tree command

The best way to learn all the advantages that the tree command offers is by using the command's own documentation, to do this run from the terminal       $ man tree

In the same way, below I offer you a list, with some of the most used options around this command:

$ tree        # Muestra directorios y ficheros
$ tree -d     # Muestra sólo directorios
$ tree -L X   # Muestra hasta X directorios de profundidad
$ tree -f     # Muestra los archivos con su respectiva ruta
$ tree -a     # Muestra todos los archivos, incluidos los ocultos.
$ tree /      # Muestra un árbol de todo nuestro sistema
$ tree -ugh   # Muestra los ficheros con su respectivo propietario (-u),
el grupo (-g) y el tamaño de cada archivo (-h)
$ tree -H . -o tudirectorio.html # Exporta tu árbol de directorio a un archivo

There are many other combinations of the command that can be very useful when displaying tree directories in Linux.

Remember that the parameters of this command can be combined, achieving for example «show the list of all files including hidden files with their respective path«, For this we execute tree -af

So we hope you can get the most out of this simple but useful command.

The content of the article adheres to our principles of editorial ethics. To report an error click here!.

4 comments, leave yours

Leave a Comment

Your email address will not be published. Required fields are marked with *



  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   federico said

    Very good and concise article, Lizard !. Every time the boys told me there was a Windows application that did the same thing, I would teach them the tree command. Few of them knew the MS-DOS command dir / s and other options.

  2.   Anonymous said

    I learned about this command through windows and the truth is, it seemed strange to me that linux did not have it by default but it is very comfortable once installed.

  3.   Taty aguilar said

    Excellent !!, you saved me, so many days searching until finally, thank you !!!!!

  4.   Pachu said

    Brilliant!! It worked perfect, thank you so much for the help.