How do I make a tree of all things with bash? What is the command?
Asked
Active
Viewed 2.6k times
11
-
1All things? It can be really hard. `tree` can be used for file system and `pstree` for processes. Possibly there are other `*tree` tools. Google can be invaluable here. – przemoc Mar 15 '10 at 00:24
5 Answers
9
tree /
or
find /
Update: @OP, since you have so much trouble with it, how about this alternative. On ubuntu 9.10, you should have bash 4.0 ? so try this
#!/bin/bash
shopt -s globstar
for rdir in /*/
do
for file in $rdir/**
do
echo "$file"
done
done

ghostdog74
- 327,991
- 56
- 259
- 343
-
none of them work...i'm using virtual machine, could be that? tree / says that is not installed – pedro Mar 15 '10 at 00:22
-
2If tree isn't installed on your Ubuntu machine use: `sudo aptitude install tree` – Ben S Mar 15 '10 at 00:23
-
-
findutils is a dependency of libc6, which many, many core packages (including apt!) depend on. And Ben gave correct instructions for installing `tree`. So I'm not sure what's going on. – Matthew Flaschen Mar 15 '10 at 00:39
-
1The tree package (http://packages.ubuntu.com/karmic/tree) is part of the universe packages, which might not be enabled. I would ask this question on the Ubuntu forums as it's not strictly programming related and they would likely already have resources to point you towards to help you out. – Ben S Mar 15 '10 at 00:43
7
you should probably alias this :)
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
(Warning: huge output)

meatspace
- 859
- 16
- 25
4
$ find . -print | sed -e 's;/*/;|;g;s;|; |;g'
Add alias to ~/.bash_profile
alias tree="find . -print | sed -e 's;/*/;|;g;s;|; |;g'"

Sola Zhou
- 169
- 2
- 3
3
tree -R /
and then cry because it's enormous.
On a related note, to stop the command, press CTRL+C

Ben S
- 68,394
- 30
- 171
- 212
-
-
Like I commented to ghostdog74's answer, install it with this command: `sudo aptitude install tree` – Ben S Mar 15 '10 at 00:26
-
-
@pedro You need to `hash -r` or open a different terminal in order to refresh which executables are on the path. – Jack G Aug 05 '20 at 23:09
2
Assuming you want to find something from tree, do
tree / > tree.txt
Then Ctrl + F it.

swapnil mandavkar
- 113
- 9