tree – List Directory Contents with Color

đź“… May 5, 2015
tree01ls has its place, but sometimes it is helpful to view a tree listing of a directory. Linux has the solution!

tree is a command-line program that shows the contents of a directory recursively complete with colors and nesting structure.


tree is not installed by default in Linux Mint 17.1, so install it with Synaptic or at the command line:

sudo apt-get install tree


To run, enter tree at the command prompt and watch the directory structure fly by.


By default, tree shows the contents of the current directory recursively. We can view from a specific directory by entering it as an argument.

Show contents of /bin.

tree /bin

Showing the files starting from /bin.

Show the entire file system.

tree /

tree listing contents recursively starting from root.

To save the contents to a file, redirect to a text file.

tree / > big-file-list.txt

(This can produce a file too large for gedit to process! Gedit kept crashing when I tried to open it, but Kate worked.)
Viewing man tree reveals a wealth of options. For example, to view file sizes with each file, use the -h (human-readable) option.

tree / -h

Showing files sizes with the -h option. Also shows sizes for directories (4.0K) when they appear.

How about the full path too?

tree / -hf

Showing files sizes with absolute paths.

Why not limit to three levels deep (-L 3) and save to a file?

tree -hfL 3 > big_file_list.txt

Be sure to place a space between the L and the 3. L3 will not work.

Show directories only with the -d option.

tree / -hdfL 1

One level deep from root.

tree / -hdfL 2

Two levels deep from root.

Keep in mind that some directory contents will not be listed if you do not have permissions to read them. /root is one example.

The possibilities are many, so experiment and have fun!



  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: