Displaying a Tree Directory Structure in Linux

If your are on Linux and need to list all the files in the form of a tree (a directory, all its subdirs, all subdirs of those, etc.), you can use the very handy tree command to do so. On its man page, Tree is described as a recursive directory listing program that list contents of directories in a tree-like format. This comes in handy if you want to have a depth indented listing of files.

Here is an example output of tree command showing the content of my home directory in a tree format

Installing and Using tree


The tree command should be available in most distributions. If not already there, start by installing it.

Check if the installation is successful

The tree command syntax is as follow

tree path/To/Folder

Here is an example that display the content of / directory in tree format

Using the tree command without any option should be enough most of the time. However, if you need to customize the output, here are the most common ones.

  • Display all files (hidden ones are not included in the listing).

  • Display directories only.

  • Print the username, or UID number if no username is available, of the file..

  • Display the size in a human readable format

You can use can use the --help directive to get all the options that can be used with tree.

Find this post interesting. Share it!

Leave a Comment

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