Linux: View Directory as Tree

By Xah Lee. Date: . Last updated: .

The command tree prints a dir in a visual tree format, similar to pstree for processes.

to install:

sudo apt-get install tree

For example, here's a tree view of /etc/X11 dir.

linux tree x11 dir screenshot 2013-05-24
screenshot of Linux tree command.

Tree view is useful, for example:

Useful Options

Here's some of the most useful options.

Show full path.
-L level
Specify depth.
-P pattern
Using wildcard to match file names to limit listing. For example, -P '*html' to show only html files. Note: this will still show directories even if it doesn't contain matching file.
Show dirs only.
Reverse order.
Sort output by last modification time.
List dir before files.
--filelimit n
Don't go into dir that's more than n files.
Display file type indicator. For example, “/” for dir, “*” for executable, etc.
Show file perm and type.
Print file size in human readable format.

See man tree for more options.

Directory and Files

Linux Shell Basics

Directory and Files

Compress, Archive, Download

Text Processing

User, Group, File Perm


Process, Job Control


Linux Desktop