What is the command that can be used to draw the directory tree inside the terminal emulator?
Asked
Active
Viewed 3.1e+01k times
3 Answers
272
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.

sourav c.
- 44,715
75
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'

Pablo Bernabeu
- 103

Maythux
- 84,289
-
10
-
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 Mar 08 '14 at 09:23
-
3Maythux, 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 Oct 28 '16 at 06:25
-
-
1
-d
switch. – sourav c. Mar 08 '14 at 09:21tree
works well. – Benj Aug 09 '16 at 14:40