tree command on osx bash

Using homebrew:

brew install tree

Using macports:

sudo port install tree

Using the source:

Follow these directions. (Caveat; you should use the flags/etc. that make sense.)

<rant>All systems should come with tree; I use it a lot. And we can post directory structures as text, not pics.</rant>


For a simple approach you can also add the following alias to your ~/.bashrc or ~/.zshrc file:

alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"

This results in the following:

$ tree
.
|____.git
| |____config
| |____objects
| | |____pack
| | |____info
| |____HEAD
| |____info
| | |____exclude
| |____description
| |____hooks
| | |____commit-msg.sample
| | |____pre-rebase.sample
| | |____pre-commit.sample
| | |____applypatch-msg.sample
| | |____pre-receive.sample
| | |____prepare-commit-msg.sample
| | |____post-update.sample
| | |____pre-applypatch.sample
| | |____pre-push.sample
| | |____update.sample
| |____refs
| | |____heads
| | |____tags

Found this solution here:

  • http://osxdaily.com/2016/09/09/view-folder-tree-terminal-mac-os-tree-equivalent/