How to print the directory tree in terminal

You can use tree to print the directory tree in terminal. Install tree from terminal,

sudo apt-get install tree

To see the directory tree, use

tree /path/to/folder

Or navigate to a directory and just use

tree

It has some advanced options too. You can see owner's username, groupname, date of last modification of a file/folder and so on using tree. It supports directory colors of ls so you can see colourized outputs.

See man tree for more.


You can do it easily with the following command:

find . -type d | sed -e "s/[^-][^\/]*\//  |/g" -e "s/|\([^ ]\)/|-\1/"

This command will search recursively for directories inside the parent directory and then draw the tree of the founded directories.

You may also try the following to include all of the files as well.

find | sed 's|[^/]*/|- |g'

There is a program called tree which lists directory content in a tree structure.

I think it's in the repositories (or even installed)

sudo apt install tree

tree -d /path/to/directory

Check this link for more.

Tags:

Command Line