What is the command that can be used to draw the directory tree inside the terminal emulator?

enter image description here

3 Answers 3


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


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.

  • 11
    If you wish to tree only directories use -d switch.
    – sourav c.
    Commented Mar 8, 2014 at 9:21
  • clean and easy tool
    – zhihong
    Commented Feb 16, 2015 at 15:57
  • 5
    or if you use brew on OSX. "brew install tree"
    – AshHimself
    Commented Sep 15, 2015 at 4:13
  • I was searching how to do it on Win7 + cmder : tree works well.
    – Benj
    Commented Aug 9, 2016 at 14:40
  • @AshHimself yep beat me to it. ;)
    – james-see
    Commented Aug 15, 2018 at 20:24

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 directories found.

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

find | sed 's|[^/]*/|- |g'
  • 10
    Please split and explain the above command for me. Commented Mar 8, 2014 at 9:08
  • 5
    @AvinashRaj Buddy the overall of the command is clear if you wan to learn more about sed please refer to some tutorials or google it. It's really hard to explain all sed here!
    – Maythux
    Commented Mar 8, 2014 at 9:23
  • 3
    Maythux, you're right that if you understand sed then your script is clear, but don't be fooled into thinking sed/regexes are anything but a cryptic language you've learned over the years. It's hardly intuitive - which I think is the spirit of Avinash Raj's comment.
    – aaaaaa
    Commented Oct 28, 2016 at 6:25
  • What would I need to change to ignore hidden directories?
    – cadams
    Commented Aug 14, 2017 at 19:06
  • 1
    how to leave a specific directory? Commented Nov 11, 2018 at 10:09

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .