Mac OS X equivalent of the Ubuntu "tree" command

You can get the tree command on macOS, too. If you have Homebrew:

brew install tree

If you do not have Homebrew installed, try one approach below.


Installing a package manager approach

Follow the instructions on these websites to install Homebrew, MacPorts, or Fink. Do not install more than one package manager at the same time!

Follow the prompt for whichever you installed.

For Homebrew: brew install tree

For MacPorts: sudo port install tree

For Fink: fink install tree

Installing from source approach

  1. Install the Xcode command line tools by running xcode-select --install.

  2. Download the tree source

  3. Change the Makefile to get it to work, which is also explained in @apuche's answer below. Commenting out the Linux options and uncommenting the macOS options should be enough.

  4. Then, run ./configure, then make.

  5. Now you have to move the tree binary file to a location that's in your executable path. For example:

     sudo mkdir -p /usr/local/bin
     sudo cp tree /usr/local/bin/tree
    
  6. Now edit ~/.bash_profile to include:

     export PATH="/usr/local/bin:$PATH"
    
  7. Reload the shell, and now which tree should point to /usr/local/bin/tree.


Not exactly the same, but one quick way on the Mac is:

find .

and that's it. It will list all file paths in the current directory as a list.


Or if your administrator won't let you install any of the brew, fink, port tools you can always build it from the source :

curl -O ftp://mama.indstate.edu/linux/tree/tree-1.5.3.tgz
tar xzvf tree-1.5.3.tgz
cd tree-1.5.3/
ls -al

Edit the Makefile to comment linux part and uncomment osx area:

# Linux defaults:
#CFLAGS=-ggdb -Wall -DLINUX -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
#CFLAGS=-O2 -Wall -fomit-frame-pointer -DLINUX -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
#LDFLAGS=-s

# Uncomment for OS X:
CC=cc
CFLAGS=-O2 -Wall -fomit-frame-pointer -no-cpp-precomp
LDFLAGS=
XOBJS=strverscmp.o

Optional: Forcing color output

And while you're at it, if you want to force tree to always colorize the output, you can always edit the main method of the tree.c file and add force_color=TRUE; before setLocale(LC_TYPE,"");

Finally hit make and you're done building tree for mac.

Tribute goes to Shaun Chapman for his original post on his blog.