O'Reilly logo

Linux Shell Scripting Cookbook by Sarath Lakshman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Printing directory tree

Graphically representing directories and filesystem as tree hierarchy is quite useful when preparing tutorials and documents. Also they are sometimes useful in writing certain monitoring scripts that helps to look at the filesystem using easy-to-read tree representations. Let's see how to do it.

Getting ready

The tree command is the hero that helps to print graphical trees of files and directories. Usually, tree does not come with Linux distributions. You need to install it using the package manager.

How to do it...

The following is a sample UNIX file system tree to show an example:

$ tree ~/unixfs
unixfs/
|-- bin
|   |-- cat
|   `-- ls
|-- etc
|   `-- passwd
|-- home
|   |-- pactpub
|   |   |-- automate.sh
|   |   `-- schedule
| `-- slynux ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required