11

How do I make a tree of all things with bash? What is the command?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
pedro
  • 131
  • 1
  • 1
  • 7
  • 1
    All 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 Answers5

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
  • 2
    If tree isn't installed on your Ubuntu machine use: `sudo aptitude install tree` – Ben S Mar 15 '10 at 00:23
  • the same...0 packages installed :S – pedro Mar 15 '10 at 00:26
  • 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
  • 1
    The 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
2

Assuming you want to find something from tree, do

    tree / > tree.txt

Then Ctrl + F it.